# vehicle resting on terrain

This topic is 3885 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, I am trying to write a game engine but at the moment i am having issue getting the vehicle to rest on the terrain. I can get it to sit on the terrain fine if it’s flat but when the terrain is at an angle it messes up. This is how it set up currently. The vehicle is worked out by the centre of mass then I use an offset to find the location of all 4 corners. I then apply the normal of the terrain to the object to get it to rotate correctly when one of the corners hits a new poly. The issue with this is that the centre of mass then needs to be raised enough so one of the corners doesn’t fall through the terrain and the other corner is resting on the terrain. There are to many unknowns to actual get it correct. So I am trying to come up with a new way of doing it. I have a few other ideas that I am going to play around with but if anyone can through any suggestions my way ill look into it and see if it helps.

##### Share on other sites
You'll need to take the suspension into account.

The car is a rigid body and cannot twist to let all four wheels rest on the ground if the terrain is very uneven.
At most three wheels would be on the ground if there is a hole underneath the fourth.
Another thing is that the wheels can't all be perpendicular to the surface, the suspension usually helps but not in extreme cases.

I hope this can be of some help to you.

##### Share on other sites

I am currently using a tank so the suspension doesnt need to play a part at the moment.

##### Share on other sites
Instead of rotating about the axis going through the center of mass, try rotating about the point where the tank is still touching the ground as it drives over the other object.

##### Share on other sites
Not the most physically accurate way but...

Three points define a plane. Find the height of the terrain at each of the 4 wheels. Pick the highest 3. Form a plane from those 3 points. Rotate the vehicle so that it's up vector is perpendicular to the plane. Translate it so it sits on the plane. One wheel will almost certainly not touch the ground, but that can't be helped if the vehicle is rigid anyway.

This way won't correctly model the center of mass in most cases, or handle forces which don't act directly on the center of mass. It should be fast and easy though, and it may be good enough. Also, it will make your vehicles more stable (they won't tip over) which may be good or bad depending on the game play you are going for.

##### Share on other sites
Quote:
 Original post by OptimAdamI am currently using a tank so the suspension doesnt need to play a part at the moment.

It kinda does: tanks do have suspension, and they'd have poor all-terrain capabilities if they didn't.

##### Share on other sites
As has been established, a plane is uniquely defined by three points, but you need to accommodate four, so something has to give. Suspension would be ideal, but it's quite a lot of effort to get right. Provided your terrain is reasonably well-behaved (as with a low modulus of continuity) then you can fudge it:

Project the positions of the four corners down to ground-level, and compute the mean gradients along the tank's local axes. Use these to orient the tank. Now all that remains is to find the height of the tank that minimises the error. A very simple least-squares implementation would do the trick.

The result will, in general, have all corners either passing through the ground or hovering, but the error will be minimal (without distorting the mesh, as in the suspension solution) and if the ground is 'smooth' enough, the error won't be noticeable. Provably optimal, not too difficult to implement.

##### Share on other sites
I’ve proceeded with calculating the height at each out, but i am running into a little trouble getting the height at a set point on a polygon.

I have the normal of the polygon and a point on the polygon. I also know the x and z coordinate of the wheel but I don’t know how high it should be. I’m using this formula to find the height

a =-normal.X*(wheel.X-polygonPoint.X)
b -normal.Z*(wheel.Z-polygonPoint.Z)
c = a+b
d = c/normal.Y

result = d +polygonPoint.Y

Problem i have with that is its only returning half of y. I cant double it because its accurate when the terrian is flat. Have i made a mastake in my caculations or is there an issue some where else. Or evern better a simpler forumla :)

##### Share on other sites
Fixed that, had a bracket in the wrong place.

I’m just having an issue now getting the top points behaving correctly.

When I drive up a hill the object rises but the top points don’t behave correctly. They only rise by y when I also need it to change by x. I am finding it really difficult to get it looking correct.

1. 1
2. 2
Rutin
22
3. 3
4. 4
JoeJ
15
5. 5

• 14
• 30
• 13
• 11
• 11
• ### Forum Statistics

• Total Topics
631776
• Total Posts
3002300
×