x


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 '10 at 11:34 AM

brandon 1 gravatar image

brandon 1
0 4 4 8

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

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

6 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)) 
     Jump();

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 '10 at 10:25 AM

Sriram gravatar image

Sriram
243 9 12 19

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 '13 at 07:44 AM St4rKiller070
(comments are locked)
10|3000 characters needed characters left

The default ThirdPerson-controller in Standard Assets does this.

more ▼

answered Oct 23 '10 at 12:54 PM

StephanK gravatar image

StephanK
6.4k 46 59 101

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

answered Nov 13 '10 at 01:30 PM

sonic220 gravatar image

sonic220
44 24 30 37

(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 '12 at 12:48 PM

teonicel gravatar image

teonicel
16

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

Please Walk Script in C#?

more ▼

answered Nov 19 '12 at 08:57 PM

MrSaly gravatar image

MrSaly
0

(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

By RSS:

Answers

Answers and Comments

Topics:

x4397
x2138
x1497
x190
x114

asked: Oct 23 '10 at 11:34 AM

Seen: 40862 times

Last Updated: Jun 07 '13 at 07:44 AM