- Home /
Addforce - bug with jump
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?
Answer by MjrDeathAdder · Feb 11, 2013 at 12:44 PM
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.
Thank you, now it works. But I still do not understand the reason why AddForce do that...
Answer by deltamish · Feb 11, 2013 at 02:18 PM
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
Your answer
Follow this Question
Related Questions
Confusion with AddForce with ForceMode.Acceleration 1 Answer
Erratic Physics behaviour while testing in 2 computers 0 Answers
Trying to Understand Rigidbody ForceMode Derivation 3 Answers
Object jumping while moving(with addForce) 0 Answers
add force to object that has 2 different rigid bodies 0 Answers