Hi!
I'm working on a game that features a tank running over a heightmap terrain (and other objects). I have a basic rigid body physics engine with OBB colliders, I also have the ability to cast rays that intersect the terrain. What I want to do is project 5 individual rays downward to orient the tank with the terrain. That's 1 ray per corner of the OBB, and an additional ray at its center so that things don't look weird if it drives over the edge of something. The tank is affected by gravity.
When a ray intersects the ground, I need to apply an upward impulse to the body at the intersection point which needs to counteract the downward velocity, but also move the body so that it's no longer intersecting.
So my question is... given the following inputs:
- Ray start, direction and length
- Intersection point, distance and normal
- Body linear velocity at the intersection point
How do I calculate the upward impulse to apply for that ray to keep it from sinking, or bouncing? I just want the tank to hug the terrain tightly so I'm hoping I can avoid all the spring/suspension forces that are normally applied to cars.
Thanks!