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

Started by
8 comments, last by d000hg 18 years, 5 months ago
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?
We should never stop learning...
Advertisement
Gravity.

Lizard
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
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.
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.
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.
COOOOOOOOOOOOOOOOOOL! VERY SMOOTH EXPLANATIONS! Thanks! ;)
We should never stop learning...
Heh. I like to see people get excited by math ;)
Quote:Original post by LizardCPP
Gravity.

Lizard


No. Everyone knows that it's AIF: Artificially Intelligent Falling.
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).

This topic is closed to new replies.

Advertisement