Before updating to Windows 10 you may need to return your Pro license. More information here

making a jump button

hey people what is a simple code for jumping with shift

more ▼

asked Apr 19, 2011 at 12:39 AM

avatar image

jacques 1
39 36 31 37

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

1 answer: sort voted first

var jump : float = 4f;

function Update (){


//rigidbody.velocity = Vector3(0 ,jump,0 ); rigidbody.AddForce(Vector3.up * jump);



you can use //rigidbody.velocity = Vector3(0 ,jump,0 ); or // rigidbody.AddForce(Vector3.up * jump); its up to you. This is how i would make a simple jump using rigidbody :)

hope this helps

Ok this is the Updated script, this one does not require any rigidbody it only needs a character controller. But just to let you know you don't even need to add a character controller to the player because the script will add it automatically :) once the script is added.

The script will also allow you to walk up and down using the vertical key "A, D" and using the Horizontal keys " W , S " you can rotate the player. to make sure it is working make the camera the child of the object :)

anyway's here is the script:

private var moveDirection = Vector3.zero;

     private var grounded : boolean = false;

         var gravity = 20.0;

             var JumpSpeed : float = 10;

               var rotatespeed : float = 5;

                  var speed : float = 10;

      function Update () {

var controller : CharacterController = GetComponent (CharacterController);

                  //Rotate around y -axis

  transform.Rotate(0, Input.GetAxis ("Horizontal") * rotatespeed, 0);

              //move forward / backwords Vertical

                   var forward =  transform.TransformDirection(Vector3.forward);

                           var curSpeed = speed * Input.GetAxis ("Vertical");

                                              controller.SimpleMove(forward * curSpeed);


             if (Input.GetButton("Jump")){

                             moveDirection.y = JumpSpeed;

                 moveDirection.y -= gravity * Time.deltaTime;

                     var flags = controller.Move(moveDirection * Time.deltaTime);

                                 grounded = (flags & CollisionFlags.CollidedBelow) != 0;

              @script RequireComponent(CharacterController)

more ▼

answered Apr 19, 2011 at 12:50 AM

avatar image

1k 261 213 225

it says unknown identifier: 'jump'.

Apr 19, 2011 at 02:26 AM jacques 1

Ops sorry i forgot a variable :) updated the script :)

Apr 19, 2011 at 03:37 AM MC HALO

is there anything i can do without rigidbody

Apr 19, 2011 at 10:19 PM jacques 1

yea there is you can use character controller i will update it for you so you can have the player jump with the character controller instead :)

Apr 20, 2011 at 12:13 PM MC HALO

how can i get rid of bounce, because i jump then bounce bounce bounce for a while and it shakes the camera and looks terrible

Apr 21, 2011 at 01:26 AM jacques 1
(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: Apr 19, 2011 at 12:39 AM

Seen: 6749 times

Last Updated: Apr 19, 2011 at 12:39 AM