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?

more ▼

asked Oct 23, 2010 at 11:34 AM

brandon 1 gravatar image

brandon 1
0 8 8 15

can you tell me the script you are using for your project ?

Nov 02, 2012 at 12:51 AM TechedEd
(comments are locked)
10|3000 characters needed characters left

4 answers: sort voted first

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)) 

PS - This would only work if your character is has a rigid body component attached to it and not a standard unity controller.

more ▼

answered Dec 08, 2010 at 10:25 AM

Sriram gravatar image

243 26 26 33

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.

Jun 07, 2013 at 07:44 AM St4rKiller070

just use a raycast to check if on ground, and if (onground and getbuttondown) jump;

Aug 31 at 05:06 PM ComeSweetDeath
(comments are locked)
10|3000 characters needed characters left

The default ThirdPerson-controller in Standard Assets does this.

more ▼

answered Oct 23, 2010 at 12:54 PM

StephanK gravatar image

6.5k 117 106 160

(comments are locked)
10|3000 characters needed characters left
more ▼

answered Nov 13, 2010 at 01:30 PM

sonic220 gravatar image

44 69 62 68

(comments are locked)
10|3000 characters needed characters left

//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; } }

more ▼

answered Nov 05, 2012 at 12:48 PM

teonicel gravatar image


(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Oct 23, 2010 at 11:34 AM

Seen: 49912 times

Last Updated: Aug 31 at 05:06 PM