- Home /
rigidbody addforce behaves different every time
i am using addforce to throw objects but object travel distance changes every time sometimes it goes 5 units sometimes 1 not sure why
Can you provide any code to demonstrate/reproduce the issue?
i am using this line to add force objectWorkedOn.GetComponent().AddForce(transform.forward * Time.deltaTime * throwPower);
and i have rigidbody with default values on my object, my script is pretty long so i cant reproduce it easily, time.deltatime might be the issue im not sure i am also changing angular velocity while adding force
Huh, just read the docs you linked, I didn't realize it behaved differently in the FixedUpdate loop. $$anonymous$$y apologies.
In that case I'd want to debug to confirm that the result of the force calculation is the same every time.
I would recommend using: objectWorkedOn.rigidbody.AddForce(transform.forward * throwPower, Force$$anonymous$$ode.Impulse); Force$$anonymous$$ode sets how the force is applied. Impulse is for forces applied for one frame. The default (not declaring a Force$$anonymous$$ode) is usually for forces applied over time. If you are using $$anonymous$$onodevelop when you type Force$$anonymous$$ode. you can read all the options.
Yep that too @NicRule :)
Here is the docs link for the Force$$anonymous$$odes :
http://docs.unity3d.com/ScriptReference/Force$$anonymous$$ode.html
Answer by mavii_ege · Dec 12, 2014 at 10:13 AM
i fixed the problem by using fixeldelta time im calling my function from update but its only called when key pressed and its called once so you get one inconsistent value from time.deltatime but fixeddeltatime gives a constant value so bomb power same everytime, thanks for the suggestions
That's not really a good fix, all you're doing is multiplying the force by something like 0.02.
I'd suggest using @NicRule's suggestion.
Answer by vfxjex · Jul 20, 2016 at 09:33 AM
you don't need to multiply it with "Time.deltaTime". PhysX has already added this into rigidbody and multiplaying it just making it back to be unstable. It is like having this (Time.deltaTime * Time.deltaTime).
also if dealing with single frame use rb.AddForce (x,y,z, ForceMode.Impulse) as mentioned also by @NicRule.
but if you really want to have more fixed value for jumping use rb.velocity = new Vector3(x,y,z);
Your answer
Follow this Question
Related Questions
Rigidbody-based spaceship? 1 Answer
Jumping with rigid body3d 1 Answer
rolling ball movement on different axis 0 Answers
push crate - works in editor, not on device 2 Answers
Rotation problem with spawning bullet 2 Answers