Jump to content
  • Advertisement
Sign in to follow this  
armond

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.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Quote:
Original post by LizardCPP
Gravity.

Lizard


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

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!