#### Archived

This topic is now archived and is closed to further replies.

# Terrain Collisions

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

## Recommended Posts

I have created a simply program that loads a terrain from a bitmap file and I can't seem to get the collision detection correct. I'm currently simply getting the triangle on which the camera lies, creating a plane from the three points, and plugging in X and Z values. Anyone know while this method's not working? Here's my project and code. [edited by - ms291052 on September 23, 2003 6:31:55 PM]

##### Share on other sites

1. It is a heightmap terrain with all points over 2D grid just with different height
2. You already know the triangle you are standing over, because you know X and Z coordinate
3. You now need to find out the Y coordinate over the terrain, therefore itd be best if you could draw the whole situation on a paper and try to find out. This is how I solved same problem - after you draw it on a paper (from 2 different angles), youll immediately see it.

4. Of course, you can still count intersections with plane

Avenger game

##### Share on other sites
The method I'm going to suggest might only work for terrains.

I assume that you are trying to setup a terrain on the x-z plain and therefore the y-component gives you the height.

I assume you have a terrain generation function that gives you the height component at a specified location like

GetHeight (x, z) ;

The function could be reading this from a height map, or using some perlin noise stuff, lets say.

All you have to do now is to check your viewpoints y component with the height at a particular location on the terrain. For example, suppose you are at location (x, y, z). You could check for collisions like

if (y < GetHeight (x, z)) {
// ... went below the terrain, get back
y = GetHeight (x, z) ;

HandleCollisionWithTerrain () ;
}

This should work.

[edited by - UdayK on September 24, 2003 2:37:02 AM]

##### Share on other sites
The problem with that is what happens when you start appying matricies to the heightmap. That''s the reason why it doesn''t seem to work with mine. How do you apply a matrix to a specific point?

##### Share on other sites
D3DXVec3Transform for D3DXVECTOR3

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633660
• Total Posts
3013222
×