Floor Collision Detection Problem

Started by
5 comments, last by MegadethUK 21 years, 8 months ago
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......
Advertisement
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...
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.
APE
--> Game Programming
Sorry I dont understand what you intend to mean by

"--> Game Programming"
The post was moved to the right forum.

Helpful links:
How To Ask Questions The Smart Way | Google can help with your question | Search MSDN for help with standard C or Windows functions
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

This topic is closed to new replies.

Advertisement