# mesh terrain following

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

## 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 on other sites
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).

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
5. 5
A4L
11

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633767
• Total Posts
3013739
×