- Home /
About Rigidbody2D.AddForce's duration...
I'm making some calculations for physics based AI movements, but they rely on the functionality of RigidBody2D.AddForce.
Does it apply said force for the duration of the current frame? less? more?
Is there any more convenient way to do a specific amount of work (the technical physics-y kind: W=F*d) to an object? (that's what my calculations do, in a nutshell)
Any remotely relevant discussion is appreciated
Answer by NoseKills · Aug 14, 2015 at 07:48 PM
The way I remember Box2D doing it is... all AddForce and AddTorque calls increase the rigidbody's internal Vector2 linearForces
and float torque
respectively, and every FixedUpdate those forces get applied to the object using the Time.fixedTime for F/m = a -> v0 + (a*t) = v1 and same for torque->rotation... and the internal forces are reset back to zero.
Having said that, there's a lot of variables affecting this equation (damping, friction, floating point inaccuracy...) so I hope you don't expect scientifically accurate results
Any remotely relevant discussion is appreciated
Actually it's not THAT welcome :) sorry to say. Unity answers is meant for specific questions with specific answers and all subjective discussions should happen at Unit Forums.
Thanks for the answer, Nose$$anonymous$$ills. What I meant by that last comment is that an answer that elaborates on the concepts behind the answer and explains it fully (in my opinion, your answer does this as well ;) ) is more useful than just the answer itself.
Answer by brentshermana · Aug 18, 2015 at 12:52 PM
In addition to the information provided by NoseKills, here is some useful information that allows me to get the more predictable results I want:
"Use Impulse mode:
rigidbody.Addforce(transform.up * 10, ForceMode.Impulse);
In Impulse mode, Unity applies instantly the velocity change equivalent to the force applied during 1 second. Mass and gravity will be taken into account, thus the result is a little more complicated to predict."
source: http://answers.unity3d.com/questions/202291/rigidbody-add-force.html
Your answer
Follow this Question
Related Questions
Platformer2D Player sticks to platform corners 0 Answers
increasing knockback of a rigidbody as received damage increases (like super smash) 1 Answer
Adding force at an angle 2D,Adding force at an angle 1 Answer
How much force does my 2d ball need to fly from point A to B ? 1 Answer
player jumps too high when clicking with two fingers. 2 Answers