- Home /
2D platformer jumping that feels good
I'm currently using the following code for my movement for a 2D platformer. I didn't want to use any of the character controllers since I'm using RagePixel, I would prefer to try and write something from scratch. My jumps feel a little 'spacey' at the moment and I'm not sure how to fix this. I tried playing around with enabling stronger gravity after a few seconds of being in the air and with different velocities but I can't find anything that feels right.
var isgrounded : boolean = true;
function Update ()
{
if(Input.GetKey (KeyCode.A))
{
transform.position.x -= 1.0;
}
if(Input.GetKey (KeyCode.D))
{
transform.position.x += 1.0;
}
if (Input.GetKey (KeyCode.W) && isgrounded == true)
{
rigidbody.AddForce(Vector3.up * 500);
}
}
function OnCollisionEnter(theCollision : Collision)
{
if(theCollision.gameObject.tag == "Floor")
{
isgrounded = true;
}
}
function OnCollisionExit(theCollision : Collision)
{
if(theCollision.gameObject.tag == "Floor")
{
isgrounded = false;
}
}
Answer by hvilela · Sep 26, 2012 at 09:44 PM
Use the Character Controller class or take a look on thar code so you can mimic it.
Your answer
Follow this Question
Related Questions
How to jump in 2D? 1 Answer
2D Platformer - Jump on platforms in Background 1 Answer
Problem of gravity 1 Answer
2D Platformer Jump while Running Android 1 Answer
2D jumping raycast question 0 Answers