#### Archived

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

# Floor Collision detection problem

This topic is 5886 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
I have a hard time following you... Your question is not very clearly stated. You want to determine the y coordinate of your terrain, given x and z?

This is quite easy, using plane equations. Is this what you would like to know?

Cédric

##### Share on other sites
Yeah, I agree with cedricl. Please state your problem a different way, and perhaps sketch out a picture for us.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.

##### Share on other sites
Ok,
As I said before for my terrain I have composed an array of average Y coordiantes (height) for each cell. The terain is composed of grid like matrix of vertices (4 vertices per cell 10 columns by 10 rows
100 surfaces, which means 1000 squared world units are covered.
OK, bare with me on this one.

So I have an array of 100 floats each element contains the average surface height (y coordinate) in the grid.

I have my method which takes two floats as arguments which are the x and z coordinates of the camera in the world.

When you move the camera over the terrain I need to be able to find the Y coordinate in my array by using the X and Z coordinate of the camera.

However, When you move the camera it only moves 0.5 units, so you could move the camera 20 in the x and z coordinates an still be on the same surface tile (same Y coordinate).

Using the crude diagram below, lets say we pass the camera position (x, z) = (-1, 5), this is marked A.
For this I need to say right you need to look in element 44 of the array.
Now lets say you pass in (-6, 9), you would still want the same element as each element represents 10 world units.
So if you passed (14, 24) marked B you would want element 26 of the array.

                     +z                   |    [ ][ ][ ][ ][ ]|[ ][ ][ ][ ][ ]    [ ][ ][ ][ ][ ]|[ ][ ][ ][ ][ ]    [ ][ ][ ][ ][ ]|[ ][b][ ][ ][ ]    [ ][ ][ ][ ][ ]|[ ][ ][ ][ ][ ]    [ ][ ][ ][ ][a]|[ ][ ][ ][ ][ ]-x -------------------------------- +x    [ ][ ][ ][ ][ ]|[ ][ ][ ][ ][ ]    [ ][ ][ ][ ][ ]|[ ][ ][ ][ ][ ]    [ ][ ][ ][ ][ ]|[ ][ ][ ][ ][ ]    [ ][ ][ ][ ][ ]|[ ][ ][ ][ ][ ]    [ ][ ][ ][ ][ ]|[ ][ ][ ][ ][ ]                   |                  -z

So the problem is to get from the passed (x,z) coordinate to the correct element of the array which referances the y coordinate.
If theres a better way then this please say.
Any ideas anyone?

[edited by - MegadethUK on August 15, 2002 6:49:33 AM]

##### Share on other sites
Wold a formular like this describe the problem:

tile_index = camera_position/tile_size
interpolation= camera_position % tile_size

(for x and y)

z=bilinear(interpolate_x,interpolate_y)

##### Share on other sites
I think I understand your problem... But I fail to see where the difficulty lies.

If your array is two dimensional, the problem is really simple

Y = grid[(int)(X / TileWidth)][(int)(Z / TileDepth)]

If I understood correctly your description, TileWidth = TileDepth = 10 world units.

Is this what you are looking for?

Cédric

[edited by - cedricl on August 15, 2002 1:10:02 PM]

1. 1
2. 2
3. 3
4. 4
Rutin
12
5. 5

• 12
• 18
• 10
• 14
• 10
• ### Forum Statistics

• Total Topics
632662
• Total Posts
3007702
• ### Who's Online (See full list)

There are no registered users currently online

×