- Home /
 
How to Jump, Sprint and Sneak
Hi! I am making my own game but cant write how to do things that is in the title Heres the code:
 var rb : Rigidbody;
 var isMoving = false;
 var isGrounded = true;
 var playerModel : GameObject;
 var onoff = true;
 rb = GetComponent.<Rigidbody>();
 
 
               function Start () {
}
function Update () { //isMoving if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.D)) isMoving = true; else isMoving = false; // Movement if (Input.GetKey(KeyCode.W)) {transform.position.z += 0.2;} else if (!isMoving && isGrounded) {rb.velocity = Vector3(0,0,0);}
 if (Input.GetKey(KeyCode.S))
     {transform.position.z -= 0.2;}
 else if (!isMoving && isGrounded)
     {rb.velocity = Vector3(0,0,0);}
 
 if (Input.GetKey(KeyCode.A))
     {transform.position.x -= 0.2;}
 else if (!isMoving && isGrounded)
     {rb.velocity = Vector3(0,0,0);}
 
 if (Input.GetKey(KeyCode.D))
     {transform.position.x += 0.2;}
 else if (!isMoving && isGrounded)
     {rb.velocity = Vector3(0,0,0);}
 //isGrounded
 if (playerModel.transform.position.y < 1.05)
     isGrounded = true;
 else
     isGrounded = false;
 //Debug
 if (onoff)
     Debug.Log(isGrounded);
 
               } I dont know how to make the character Jump but I thought the other two will be easy... Thanks!
I don't want to crush your spirit my friend, but this is not going in the right direction for many reasons. I strongly suggest you keep at it, but in a smarter way.
i.e. find a tutorial about a game where you can do all these things. Follow it to a tee!
Your answer
 
             Follow this Question
Related Questions
Patching glitches 1 Answer
How can I stop the fps controller jumping up slopes? 1 Answer
Physics Based Sprint and Jump? 2 Answers
How to sprint and have a stamina bar? 0 Answers