Sign in to follow this  
armond

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

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?

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this