# How do tanks/vehicles stay on ground in 3D RTS?

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

## Recommended Posts

Hi, I was wondering how the tanks would stay close to the ground in 3D RTS games... What is the logic and computation involved? I mean... Maps in 3D RTS games aren't flat like in 2D RTS games... Probably the tanks would be bend a certain degree while running eh?

Gravity.

Lizard

##### Share on other sites
A height-map is usually stored as a 2D grid of height values in some form. You simply find which point the unit is nearest to and use iterpolation to find the correct height between them

##### Share on other sites
To make the tank follow the ground, you would have to find the angle of the poly underneath the tank and match the tank's angle to the poly's I'd reckon. That, or use an axle trace of somekind. As to making it stay on the ground, just apply a y velocity to it and make it collide with the ground.

##### Share on other sites
One method is to use ground clamping and terrain following. A basic explanation of terrain following:
1: Create a line going straight down from each corner of the tank.
2: Find which polygons in the terrain mesh those lines collide with.
3: Average the surface normals of those polygons. Set the y-vector of the tank's matrix to that average.
To clamp the tank to the ground:
4: Create a line going straight down through the center of the tank.
5: Find the point where this line intersects the terrain mesh.
6: Translate the position of the tank up or down so its sits on that point.

##### Share on other sites
the cross product of two vectors is a vector perpendicular to the two. Each triangle has three sides. If you take the cross product of two of them you get a vector that is a surface normal. It might face up or down. If it points down negate it. Normalize it to length one. Now take the cross product of it and an up vector. Normalize it. Now take the arc sine of it, because the cross product == length(A)*length(B)*sin(angle_between). This gets you the angle between the triangle normal and the up vector. Now rotate your object by this angle and it will lie on the surface correctly, well this part covers the angle part.

##### Share on other sites
COOOOOOOOOOOOOOOOOOL! VERY SMOOTH EXPLANATIONS! Thanks! ;)

##### Share on other sites
Heh. I like to see people get excited by math ;)

##### Share on other sites
Quote:
 Original post by LizardCPPGravity.Lizard

No. Everyone knows that it's AIF: Artificially Intelligent Falling.

##### Share on other sites
Terrain following looks to be reasonably well explained already, but I can show you the way I do it in my code if you email me (see my profile for address).

1. 1
2. 2
Rutin
19
3. 3
JoeJ
16
4. 4
5. 5

• 35
• 23
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631700
• Total Posts
3001808
×