Hello Unity Community!

Im having a issue, where i want to pre-simulate paths that a rigidBody takes for UI/Feedback purposes, but i am having a hard time “getting it right”.

So for my rigid body lets say for brevity sake that i do could do a simple thing like:

``````newRigidBody.transform.position = startPosition;
``````

Somewhere else in my code i want to know what that would mean before it happens. So every update i do something like:

``````    //Calling this every frame:
private void CalculatePath(Vector3 StartPosition, Vector3 InitialVelocity)
{
int plots = 20;
float t = Time.fixedTimeStep;
Vector3 pos = StartPos;
Vector3 vel = InitialVelocity;
for(int i = 0; i < plots;i++)
{
//As far as i can tell from the documentation "Adding Force" is just
// rigidBodyMass*(force)*t^2 ? Remember im trying to replicate what
// happens to my rigidBody
vel = vel + 1*(CalculateAffectors(pos))*t*t;
pos = pos + vel * t;
}
}
// Here i get everything that my rigidBody will be "pulled" by on this path (gravity)
private void CalculateAffectors(Vector 3 position)
{
Vector3 force = Vector3.zero;
for(int i = 0; i < Affectors.Length; i++)
{
if(Vector3.Distace(Affectors*.position, position) < minDistance)*
``````

{
Vector3 direction = Affectors*.position - position;*
force = force+(direction/direction.sqrMagnitude * Affectors*.mass);*
}
}
return force;
}
So first of all, this does not actually plot points that follow the path that the rigidBody takes (which at the bottom the line is my problem), but my questions are:
A) Since i am using AddForce() - how can i deduct my initial velocity from that? (since it’s over time i am unsure - doing “CalulatePath(pos, mass*(direction*power)tt” does not work.
B) When a rigidBody is being affected by several AddForce()(Gravity for example) calls every fixed update, how can i reliably simulate that in one loop? Or rather the logic used to move my rigidBodies is how i want it i.e using addForce every frame - how to calculate that as a velocity change in my “plotting”.
C) is my math even right? The problem right now is that it looks “almost” right as in, my paths are very close to what points i can query during the rigidBody’s traversal, but it seems they get off by a a larger and larger margin (1:1, 1:1.1, 1:2, 1:10 ect).
I tried applying the affectors “one at a time”, tried firering my rigidBodies with ForceMode.VelocityChange (since then the initial velocity of my rigidBody should be the same as what i can pass into my Paths function - but it’s not, far from it hehe).
I think i have been looking at this too much maybe, switching around ordering / numbers / vectors and at this point, you guys are my only hope!
Thanks!

Unity uses PhysX, which is a very complete and complex physics simulation.

If you want to know about how it calculates motion, you can google PhysX but be prepared for heavy and complex math.

If you want to be able to predict simple physics behavior its probably better to create your own simple f=MA physics model.