- Home /
Rigidbody AddForce Forcemode.Impulse not working 2D game...
Every time i try to use addforce with impulse as the forcemode, the object will not jump, but if i remove the impulse forcemode it will jump, what i am doing wrong :S?
this is my script...
void Update()
{
if (Input.GetKeyDown(KeyCode.W)) {
Vector3 _jump = new Vector3(0,10,0);
this.gameObject.rigidbody.AddForce(_jump, ForceMode.Impulse);
}
}
Answer by IsaiahKelly · May 16, 2015 at 06:13 AM
Impossible to know exactly without more info, since many things could be effecting this (gravity, drag, mass, other forces, etc.) However, if you're using a Rigidbody2D then your code should probably be:
gameObject.rigidbody2D.AddForce (Vector2, ForceMode.Impulse)
You should also be caching the Rigidbody reference in OnStart for best performance.
Holy S"#$ i'm an idiot xD Of course im using a 2D Rigidbody x'DD If im making a 2D game (2D project setting) it's a rigibody2D, now it's working :D thank youuuuuu :D!
Answer by luislodosm · Aug 10, 2016 at 07:12 AM
Use ForceMode2D instead of ForceMode:
gameObject.rigidbody2D.AddForce (Vector2, ForceMode2D.Impulse);
Your answer
Follow this Question
Related Questions
Difference and uses of rigidbody force modes ? 2 Answers
Confusion with AddForce with ForceMode.Acceleration 1 Answer
Addforce - bug with jump 2 Answers
Erratic Physics behaviour while testing in 2 computers 0 Answers
Rotation problem with spawning bullet 2 Answers