Hello, I would think that my code would work fine for jumps, but each time I jump the height is different. It changes with x velocity for some reason, is there some way to make it consistent? could it have something to do with the Delta time?
relevant code:
function Update () {
animTimer++;
rigidbody.AddForce(Input.GetAxis("Horizontal") * horizontalSpeed * Time.deltaTime * 60,0,0);
rigidbody.velocity.x = Mathf.Clamp(rigidbody.velocity.x,-6,6);
if (Input.GetKeyDown(KeyCode.UpArrow) && isGrounded)
{
rigidbody.AddForce(0,jumpSpeed * Time.deltaTime * 60,0);
}
if (animTimer >= animSpeed)
{
frame++;
animTimer = 0;
}
if (Input.GetAxis("Horizontal") < 0) //if I'm pressing right
{
lastKeyPressed = "left";
if (isGrounded)
{
animLayer = 0;
}
else
{
animLayer = 4;
}
}
if (Input.GetAxis("Horizontal") > 0) //if I'm pressing right
{
lastKeyPressed = "right";
if (isGrounded)
{
animLayer = 1;
}
else
{
animLayer = 5;
}
}
if (!Input.GetAxis("Horizontal") && isGrounded) //if I'm pressing right
{
if (lastKeyPressed == "right")
{
animLayer = 2;
}
if (lastKeyPressed == "left")
{
animLayer = 3;
}
animTimer = 0;
frame = 0;
}
rigidbody.velocity.x = rigidbody.velocity.x * friction;
renderer.material.mainTextureOffset = Vector2(xOffset * frame, yOffset *animLayer);
}
function OnCollisionStay()
{
isGrounded = true;
}
function OnCollisionExit()
{
isGrounded = false;
}