# Terrain Collosion

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

## Recommended Posts

Hey, I am creating a top-down style game that is *not* tile based. The terrian i use is a basic heighmap. So i am wondering how to create a 2-dimensional collision map from a heigh map. I for example want areas with an angle above 45 degrees not be passable. greetings, Halan

##### Share on other sites
For my terrain I use ellipsoid (player) vs polygon collision.

By getting the players x,y position, I can quickly determine which polygon in the terrain the player is standing. I then check collision with that polygon and the surrounding ones (to a certain threshold).

If the normal of a polygons angle is > 45 degrees then i cause the player to slide down the tile if the angle is less than 45 degrees then I only offset the players y-position to sit on top of the terrain and don't modify x and z to prevent the player sliding down shallow slopes.

##### Share on other sites
Yeah i wanted the player collosion to be a simple circle as it is easy to be calculated. I think i also don'T need the slidign down as i want to have natural boundaries in my game world.

I think i willl just go for squares the player will collide with.
Basically if one of the squares edges is higher than 1 meter compared to the other i will it make collide with the player.

Is that a nice behaviour?

greets,
Halan

##### Share on other sites
I think the most simple way to check for >=45 degree angles is to check whether the height difference between the cell("tile") you're standing in and the target height point/vertex is greater or equal to the width/depth you have defined for your terrain cells.

In case that didn't make sense (and I'm sure it didn't): if for example your cells are 5.0 units wide and deep, any height difference between two points being >= 5.0 would also make their angle >=45 degrees. So in your case choosing 1.0 might or might not work, depending on how large your terrain cells are (if they were 100x100 for example, then a difference of 1.0 wouldn't even be visible, slope-wise).

I don't have the actual math to back this up, it just logically/visually seems to make sense to me. Someone please correct me if I'm wrong here :)

##### Share on other sites
Yeah sure i meant the cells to be 1x1. You are of course completely correct.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

• 10
• 11
• 13
• 9
• 11
• ### Forum Statistics

• Total Topics
634087
• Total Posts
3015445
×