- Home /
Question by
Mitch Wardle · Apr 07, 2014 at 05:03 AM ·
2d2d-platformerjumpplatformer
Make a 2D jump?
I was wondering if anyone could help me out on a little platformer I'm trying to create here, I know how to make movement like left and right but dont know how to add jumping? I'm quite knowledgeable when it comes to Javascript, but not too good with the unity API. So if anyone could help me write a jump script that would be great; here is my movement script
//set movement keys
var jumpKey: KeyCode;//set jump key in inspector
var moveLeft: KeyCode;//set left key in inspector
var moveRight: KeyCode;//set right key in inspector
//sets player speed
private var speed: float = 5.0f;
//sets player jump height
private var jumpHeight: int = 30;
function Start(){
}
function Update(){
if(Input.GetKey(moveLeft)){//if left arrow is pressed
transform.position -= Vector3.right * speed * Time.deltaTime;
}
else if(Input.GetKey(moveRight)){//if right arrow is pressed
transform.position += Vector3.right * speed * Time.deltaTime;
}
else if(Input.GetKey(jumpKey)){
//Jump code goes here
}
}
Comment
Simplest is :: add rigidbody component to your player and the write this in your jump code :: rigidbody.addForce(Vector3.up *speed)
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Jump 2D error 1 Answer
Moving platform player bounce when moving down 1 Answer
Character clips into the ground in 2D platformer 0 Answers
Velocity in Unity2D 2 Answers