- Home /
Question by
xcelvibes · Apr 30, 2020 at 10:52 AM ·
charactercontrollerjumpjumpingthird person controllerbasics
How would I get my character to be able to move while in the air after a jump?
The thing is after I remove the anim.SetTrigger("isJumping") I am able to move in the air but I wont have a jump animation.
Code
public class JumpingandSHit : MonoBehaviour { private CharacterController controller; Animator anim;
private float verticalVelocity;
private float gravity = 14.0f;
private float jumpForce = 10.0f;
// Start is called before the first frame update
void Start()
{
controller = GetComponent<CharacterController>();
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
if (controller.isGrounded)
{
verticalVelocity = -gravity * Time.deltaTime;
if (Input.GetKeyDown(KeyCode.Space))
{
verticalVelocity = jumpForce;
anim.SetTrigger("isJumping");
}
}
else
{
verticalVelocity -= gravity * Time.deltaTime;
}
Vector3 moveVector = new Vector3(0, verticalVelocity, 0);
controller.Move(moveVector * Time.deltaTime);
}
}
Comment