Hi, i’m new to unity and trying to write a simple player movement script on my own, with a jump set on space bar that has the basic rules of a video game jump (no jump mid-air, jump during a movement is taken in account…)
Here is what i came up with :
In FixedUpdate :
if (Input.GetKeyDown("space") && transform.position.y < 0.5f )
{
Jump();
}
void Jump(){
rigidBody.AddForce (Vector3.up * jumpHeight);
}
Jump is outside of FixedUpdate of course.
My problem is that sometimes, the player object will only move by a few units and sometimes it’ll make a huge jump. So far i couldn’t find any pattern to understand the logic between the different jumps.
Is there a way to code a more reliable jump, i want to set a height and have my player object do a nice and smooth jump of that height. and if the player is moving during the jump, i want the object to jump in that direction.
Thanks for your help