Hello, i write own player controller, use rigidbody and box collider (for 2d game).
I use Addfoce for jump.
void FixedUpdate () {
if (Input.GetButtonDown (“Jump”))
{
rigidbody.AddForce(Vector3.up * Jump,ForceMode.Impulse);
}
}
It work fine, but sometimes player can jump higher than it should.
I tried to remove ForceMode or chane to other. I tried to add * Time.deltatime.
But nothing helps. What I’m doing wrong?
What I’m using which seems to be working fine is:
void Update() {
if(Input.GetButtonDown(KeyCode.Space)){
rigidbody.velocity = new Vector3(0, JumpVelocity, 0);
}
}
But my assumption is that this is going to be the same. Another thing is maybe collision detection is adding an upward force at the same time. Best of luck.
- But I still do not understand the
reason why AddForce do that…
The reason to that is when the character is on higher ground His Z axis wiil be more to put in simpler terms
take z =1 as lower ground and take z =2 for higher ground and jumpforce as 2 .When you are in lower ground and when you press jump 1 is multiplied by 2 which is 2.But when you are in higher ground and when you press jump (z =2) 2 will be multiplied by 2 which gives four so as you can see they both are not the same but where as velocity doesnot change wether he is in higher or lower region as long as he is in contact with the ground