- Home /
Character Movement and Jumping Script?
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?
can you tell me the script you are using for your project ?
pls send me the available movement scripts
send me as soon as possible
Answer by Sriram · Dec 08, 2010 at 10:25 AM
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.
But what if player holds long time jump button? Character would jump too high ^^ I think better would be "GetButtonDown" but it will be wrong too, when player fast push button several times.
just use a raycast to check if on ground, and if (onground and getbuttondown) jump;
Answer by StephanK · Oct 23, 2010 at 12:54 PM
The default ThirdPerson-controller in Standard Assets does this.
Answer by teonicel · Nov 05, 2012 at 12:48 PM
//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; } }
Your answer
Follow this Question
Related Questions
Simple Walking/Running Script 1 Answer
Why can't I jump and run at the same time? c# 1 Answer
Movement in my terrain ? 2 Answers
Player Falls Much Slower While Moving 2 Answers
Vehicle/car/ Movement 0 Answers