My character have an rigibody and
able to move around and jump
both work perfectly separately but when my character is jump to the air and move,
the character can walk on the sky without falling
I believe there are some problem on my
moveCharacterAndSetAnimation’s movement vector
but I cannot figure what should I change
void FixedUpdate () {
myPlayer.updateCharacterMovement ();
checkJump ();
}
void checkJump(){
if(Input.GetKey(KeyCode.Space)&&isGrounded){
jumpCharacter();
}
}
void jumpCharacter(){
myPlayer.rb.AddForce(myPlayer.playerGameObject.transform.up * 1000, ForceMode.Acceleration);
isGrounded = false;
}
public void updateCharacterMovement(){
float horizontal = Input.GetAxis ("Horizontal");
float vertical = Input.GetAxis ("Vertical");
if (isMoving (horizontal, vertical)) {
moveCharacterAndSetAnimation (horizontal, vertical);
} else {
idleCharacterAndSetAnimation();
}
}
void moveCharacterAndSetAnimation(float horizontal, float vertical){
Vector3 movement = new Vector3 (horizontal, 0f, vertical);
setAnimation (animationId.running);
playerGameObject.transform.forward = Vector3.Normalize (movement);
rb.velocity = movement * speed;
}