【发布时间】:2019-05-20 06:01:52
【问题描述】:
我的角色动作很好,跳跃也很好。但是在跳跃时,他只是朝着他来的方向直线移动,在空中你不能旋转或移动他。怎么可能?
来自更新函数:
if (controller.isGrounded)
{
moveD = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
moveD = transform.TransformDirection(moveD.normalized) * speed;
moveDA = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
if (moveDA.magnitude > 0)
{
gameObject.transform.GetChild(0).LookAt(gameObject.transform.position + moveDA, Vector3.up);
}
if (Input.GetButton("Jump"))
{
moveD.y = jumpSpeed;
}
}
moveD.y = moveD.y - (gravity * Time.deltaTime);
controller.Move(moveD * Time.deltaTime);
【问题讨论】:
-
你需要将你的移动、旋转和跳跃逻辑分开。现在他们都在一起了,你的答案就在第一行:if...isGrounded。