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;
}
}