【发布时间】:2023-01-30 22:06:28
【问题描述】:
再次问好我的朋友们。
我正在尝试在 Unity 中制作一款 3D 游戏,我正在尝试使用简单的 WASD 键移动我的角色。
然而,它仅从一个方向取得成功。从相反的方向看,控件似乎是相反的。即使我用鼠标环顾四周。该游戏被认为是第一人称射击游戏(FPS)。
播放器代码是:
[SerializeField]
private NavMeshAgent navMeshAgent;
// Start is called before the first frame update
void Start()
{
controller = GetComponent<CharacterController>();
}
// Update is called once per frame
void Update()
{
Vector3 direction = new Vector3(Input.GetAxis("Horizontal1"), 0, Input.GetAxis("Vertical1"));
Vector3 velocity = direction * speed;
velocity.y -= gravity;
velocity = transform.TransformDirection(velocity);
controller.Move(direction * Time.deltaTime);
transform.position = navMeshAgent.nextPosition;
}
我应该怎么办?我将衷心感谢您的帮助。
【问题讨论】:
-
你也可以随时使用它
float h = Input.GetAxis("Horizontal");float v = Input.GetAxis("Vertical");`Vector3 forward = transform.forward * v * speed * Time.deltaTime;Vector3 right = transform.right * h * speed * Time.deltaTime;cc.Move(forward + right);
标签: c# unity3d frame-rate