I have a script that allows for forwards, backwards, left and right movement but I can't jump. It's a third person game, so is there any script that allows jumping but also allows WASD/arrow keys movement?
This is a very basic code structure of how you could get your character to jump.
Add a public variable
`public float JumpSpeed = 100.0f;`
Then write a function for your jump
void Jump()
{
animation.Play("jump_pose");
rigidbody.AddForce(Vector3.up *JumpSpeed);
}
Then in your update function just check if the player has pressed the jump button and if he has execute jump
if (Input.GetButton(JumpButton))
Jump();
PS - This would only work if your character is has a rigid body component attached to it and not a standard unity controller.
//C# example
private float JUMP_FORCE = 10.0f;
private bool isTouchingMap;
void Update () {
if(Input.GetKeyUp(KeyCode.Space)){
jump();
}
}
public void jump(){
//rigidbody.AddForce(Vector3.up * JUMP_FORCE);
if(isTouchingMap){
rigidbody.velocity += Vector3.up * JUMP_FORCE;
}
}
The default ThirdPerson-controller in Standard Assets does this.