I'm using c# for unity2d, and whenever I do addforce to the game object, it always jumps at a different height. I've tried putting it in fixed update and update, and i'm not using time.deltatime either. I've also tried directly changing the velocity, but it still is inconsistent. My gravity is -9.81 and the gravity scale is 3. Mass for my object is around 2.7, but it should still be consistent, right? sorry I'm really new to this Code (CSharp): if (Input.GetKeyDown (KeyCode.UpArrow)) { GetComponent<Rigidbody2D> ().velocity = new Vector2 (0, 0); GetComponent<Rigidbody2D> ().AddForce (new Vector2 (0, 1750), ForceMode2D.Impulse); }
Are you getting longer jumps the longer you hold the UpArrow down? I think you need a boolean that is set to True when you first start jumping but wont do your jump code if you are already jumping. You then set the boolean to false when you collide with the ground again.
my jumps are random regardless of the length or where i initiate the jump. also if it is getkeydown should the code only execute once? hmm im confused
No, you are simply checking if the Key is down at the time the code runs. So if this is being done as part of the update function you are essentially checking and running that code once per frame.