#### Archived

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

# Floor Collision Detection Problem

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

## Recommended Posts

I might just be being stupid, if this is a case, please feel free to form an orderly queue to hit me with a large stick. Any the Problem! I have created a 3D terrain with various hills and want my player (the camera) to maintain an height above the hilly surface as you move using the keys etc. To do this, which may or may not be the best way...if not someone say a better. As I plotted my vertices forming a grid like matrix, I grab every other four set of vertices and get the average Y (height) coordinate and stuff them into a member variable (using classes). The Grid is formed of 10 colums by 10 rows each tile (cell) is 10 world units. These values are variables and can be changed. The camera moves 0.5 world units per frame in the selected direction if any. Sounds logical..so far dont it? Right, I then created a metho to which takes two arguments of type float, which are the X and Z coordinates of the camera. From this I need to determine, which element of my array containing the surface elements should be used. Note that there is not a one to one relationship here. As there are like 10 world units per cell the player can move like 20 (0.5 world units per movement) and still be on the same cell. I have been trying for like 3 days on what at first seemed like a simple problem. I have now pulled out all of my hair....someone please help......

##### Share on other sites
why don''t you just make some kind of scene graph (in a quadtree form) and then search for the exact tri the cams on and then taking the exact height (as you know the exact tri) just add the difference. If you can access all the data of the grid directly then you don''t even need to worry about the scene graph...

##### Share on other sites
What''s the problem? Is it you can''t find what cell your over or you can''t find the height once you''re over it?

If you can''t find the tile:
Since all your tiles are the same size (10 units) dividing your player''s x and z coodinates by 10 should give you the correct tile unless you''ve performed some scaling in between drawing them. Make sure you tank the integer of the result.

There''s 2 methods I can think of to get the height after that.

The first is to interpolate along 2 opposite sides of the cell and them interpolate between the results to get the point where your player/camera is above.

The second is to shoot a ray from your position straight down the Y-axis and perform a ray/plane intersection for the polygon you are above.

##### Share on other sites
--> Game Programming

##### Share on other sites
Sorry I dont understand what you intend to mean by

"--> Game Programming"

##### Share on other sites
The post was moved to the right forum.

How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions

##### Share on other sites
quote:
Original post by siaspete
The post was moved to the right forum.

And what forum was it in before it was moved?

Anyway, this a cross-post. It''s already in the Maths-Physics forum. See here.

Cédric

1. 1
2. 2
Rutin
23
3. 3
JoeJ
20
4. 4
5. 5
gaxio
13

• 24
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631734
• Total Posts
3001933
×

## Important Information

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!