当他奔跑时,他陷入了空中并且可以在空中行走?这是我跳的怪人,这时我已经尝试了几种不同的跳技术,并且在这一件事上已经做了一个多星期的研究。动画本身没有错,当他空闲时,动画会播放,但CharacterController对撞机仍停留在地面上。
Animator anim;
public float jumpSpeed = 8.0F;
private Vector3 moveDirection = Vector3.zero;
private CharacterController _charController;
public float speed = 6.0f;
public float gravity = 10f;
private float verticalVelocity;
private float jumpForce = 5.0f;
private float gravityJump = 14.0f;
void Start()
{
_charController = GetComponent<CharacterController>();
anim = GetComponent<Animator>();
}
void Update()
{
if (_charController.isGrounded)
{
verticalVelocity = -gravityJump * Time.deltaTime;
if (Input.GetKeyDown(KeyCode.Space))
{
anim.SetTrigger("Jump");
float deltaX = Input.GetAxis("Horizontal") * speed;
float deltaZ = Input.GetAxis("Vertical") * speed;
Vector3 movement = new Vector3(deltaX, 0, deltaZ);
movement = Vector3.ClampMagnitude(movement, speed);
movement.y = gravity;
movement *= Time.deltaTime;
movement = transform.TransformDirection(movement);
_charController.Move(movement);
verticalVelocity = jumpForce;
}
}
else
{
verticalVelocity -= gravityJump * Time.deltaTime;
}
Vector3 jumpVector = new Vector3(0, verticalVelocity, 0);
_charController.Move(jumpVector * Time.deltaTime);
}
}