Jump to content
  • Advertisement
Sign in to follow this  
bovinedragon

mesh terrain following

This topic is 3919 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

Ive looked at a lot of sites, but i cant seem to get it. What i basicly have is a mesh terrain, that is composed of a bunch of triangles. I want to be able to have a character walk along the mesh. This would mean basicly if i move, find the triangle that is under the character, and calculate from the x and y corrdinates the z coordinate that is on the triangle. I cant seem to get this to work. I have all of the vertexes of the triangles in the terrain mesh, and the vertex normals. can someone explain how you pick which triangle is under the character, and calculate the z coordinate?

Share this post


Link to post
Share on other sites
Advertisement
What you want to find is a line intersect triangle function that gives you the point. The triangle will be the half quad on the mesh (watch out for alternating herringbone diagonals used on some meshes) which is easily found since the mesh is a regular axis aligned grid. The line is your XY position extended straight down (2 Z values to define a line segment...). The Z value of the resulting 3D point will be the surface contact point and you object sitting on the surface would be built up from there.

I did this like 5 years ago taking the generalized line intersect triangle code and optimizing it for right triangles (which your heightmap grid is made of).


GOOGLE 'Line Intersect Triangle'

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!