试图实现类似于《洛克人战斗网络》的动作,试图实现《洛克人战斗网络》系列中的特定动作

时间:2019-05-09 18:44:47

标签: c# visual-studio unity3d

我正在尝试像《洛克人战斗网络》系列那样实现移动,在那些以3x3网格移动的游戏中。方向盘上的每个输入都会将您移至网格中的另一个图块。

我有半有效的代码,但是我得到的怪异实例中,按与上一个方向不同的方向将您对角移动。这是我的代码:

public Vector3 IncrementInputPos()
 {
     Vector3 originPoint = new Vector3(0, 0, 0);
     Vector3 playerPos = gameObject.transform.position;
     if (Input.GetKeyDown(KeyCode.D))
     {
         playerPos += originPoint + new Vector3 (1f,playerPos.y,playerPos.z);
     }
     if (Input.GetKeyDown(KeyCode.A))
     {
         playerPos -= originPoint + new Vector3(1f, playerPos.y, playerPos.z);
     }
     if (Input.GetKeyDown(KeyCode.W))
     {
         playerPos += originPoint + new Vector3(playerPos.x, 1f, playerPos.z);
     }
     if (Input.GetKeyDown(KeyCode.S))
     {
         playerPos -= originPoint + new Vector3(playerPos.x, 1f, playerPos.z);
     }
     return playerPos;
     }

您认为这里发生了什么?另外,考虑到我希望网格中的图块与玩家互动(例如,它们是否冻结或着火还是什么),这是实现运动的最佳方法吗?

祝一切顺利,谢谢!

0 个答案:

没有答案