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
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.
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: Rigidbody Add Force - Questions & Answers - Unity Discussions