Advertisement

Collision Detection with terrain

Started by July 03, 2002 03:42 PM
1 comment, last by kyojin 22 years, 7 months ago
I was wondering what would be a good way to do collision detection when a player walks across terrain. Mainly, the problem is what to do when the player goes up a slope... since he is already in contact with the ground, when he moves forward the next frame, he will be inside the terrain. Whats a good way to handle this? Thanks for your input in advance. Notes: I''m planning on using sphere sweeps and boudning boxes for collision detection. So I will beable to detect collisions easily, but just dont know what to do in this case.
terrain? if you know the height of it at any point, you could do this:

oPlayer->SetZ(oTerrain->GetHeightAt(oPlayer->GetX(), oPlayer->GetY()));

that is if your player's feet are where his origin is.

that way the player won't fall through ground. but if you want to collide with buildings or trees, you have to have some real collision detection + responce code.

try using google, there's a lot of info on such a popular topic out there.

edit: height, not heigh.
edit2: forgot one extra ) bracket.

---
shurcool
my project

[edited by - shurcool on July 3, 2002 7:01:59 PM]
Advertisement
Lets see, you could get a vector of the direction you are traveling(with the magnitude being how fast you are moving), and test that vector against all the triangles in the area(using a space partitioning algo). If that vector passes through a triangle, then you know you hit one, and you need to test further. Find the point of intersection and only allow you to move to that point then recursively do this until you have no velocity which would hopefully give you a sliding effect. Im sure i missed a few parts, but i would be happy to help you out if you need further explanation, just feel free to email me at vze323wh@verizon.net. I am fairly bad at explaining things a lot of times.
http://www.thedizzle.com

This topic is closed to new replies.

Advertisement