I am working through the car physic example in network example - hopefully to notate the script to understand the calculations better.
Can someone help me understand the last line of the code below - where the magnitude of the velocity minus the forward direction is used. Wont the magnitude essentially always be the same?
No. flatDir is the direction that the car is facing (projected onto the horizontal plane), while flatVel is the velocity at which the car is traveling (again projected onto the horizontal plane). These two quantities are not always aligned.
Consider, for example, what happens when the car is making a left turn. In that case, relative to the car, flatVel will face left while flatDir still faces forward.
I assume that diff is used somewhere further down the line to apply/compute drag forces on the car? Something like that would make sense to me.
But is not the magnitude (the length) always the same? Is not the velocity measured from the center of the rigidbody and the forward direction too? So if the model is moving, all components are moving.
I know there is a magnitude difference but I am trying to understand why there is?
Let’s assume that flatDir is always (0, 0, 1). In that case, if flatVel is also (0, 0, 1) then diff is 0. If, on the other hand, flatVel is (0, 0, -1) then diff is 2. Ergo, diff is not a constant quantity!