With the help of some stronger comparisons in this thread, I can clearly see how unexpected this could be.
Though, I’m afraid, there are no easy steps to correct what you just outlined. As Edy mentioned, this has been like that since forever, and, truth to be told, the probability of this being addressed soon is not very high. But let me assure you that if a solution happens to emerge, there would be no reasons to hold it from being delivered to you guys.
Now, for the curious ones, I’ll explain some of the technical details behind the walls.
As you know, physics are simulated at a fixed frequency. Every physics frame, FixedUpdate is invoked, and the purpose of this is to let the scripts do the final adjustments right before the simulation step runs.
When simulation runs it does this:
- perform suspension raycasts
- update vehicles (spring forces, tire forces, etc)
- update everything else (Rigidbodies, colliders, triggers, etc)
That means every frame all wheels are put on the ground, and their positions are later used to work out the springs compressions, tire forces and so on. After that, everything else gets updated.
Returning back to the GetGroundHit question. You might be able to guess already that GetGroundHit simply returns the cached raycast hit position computed last physics frame. Since that time, of course, the vehicle has moved a little, so did all surrounding bodies. Thus the inaccuracy you observe. GetGroundHit works this way for performance reasons, where you sacrifice some fair bit of accuracy to save on additional raycasts.
Because the only linear degree of freedom of wheels is moving along the suspension travel direction, GetWorldPose reuses only the suspension compression from the last physics frame. For that reason, I guess, you could try approximating the ground hit position with the base point of the wheel. That would still lag one frame along the suspension travel direction, but, at the very least, is not expected to stay behind your moving vehicle as you get with GetGroundHit.
The only way to get the exact ground hit point without any lag, that I have right on top of my mind, is to put together a script that would update wheels’ touch positions by performing additional raycasts every time after FixedUpdate was called. Probably having your own GetGroundHit implementation that would return the cached ground hit until FixedUpdate was called, and after that cast rays the very first time it gets called, etc.
Hope this helps. Anthony.
–
If it was useful, you might also get interested in this document by me as well: WC-info.pdf | DocDroid