3D collision help

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

Recommended Posts

Im making a Zelda type RPG and I want to have which ever level/town/dungeon the player is in loaded as one model and have the player move around within the area. I have the model loaded and the player moving around with the camera following without collisions. Ive only ever done bounding box collisions and Ive read about some other ways of doing collisions but Im not really sure how to do this or what kind of collision detection to use. If anyone could point me in the right direction it would very helpful :D

Share on other sites
I would make the dungeon two or three different models.

One: The bottom floor. Somehow convert this into a heightmap and use this to move around.

Two: The walls and ceiling. I'd somehow get all the verteci's and see if Link hits any of them.

Three: I'd set the 'other' object in the map *i.e. water you can't walk on, or spikes sticking out* as seperate objects instead of on the map.

If your map is very large, I'd look up the usage of Octrees. If it is simple for every sector, then I'd go ahead with AABB Box collision. Box collision is the function in wich you test collision around an object with the shape of a box:

/*Assuming you won't use Y collisions*/Vector2D Player_LeftUp(-2,2);Vector2D Player_RightDown(2,-2);Vector2D PlayerPos(0,0);Block Object(4,8,8,4); //Left x is Ax while right x is Bx. Vice versa for Y'sVector2D ObjectPos(10,10);bool PossibleCollision(Vector * PlayerA, Vector * PlayerB, Block * block){if(PlayerA.x >= block.Ax && PlayerB.x <= block.Bx && PlayerA.y <= block.Ay && PlayerB.y >= block.By){return true;}return false;}void GameUpdate(){Player_LeftUp.x = Player_LeftUp.x + Player_Pos.x;Player_RightDown.x = Player_RightDown.x + Player_Pos.x;Player_LeftUp.y = Player_LeftUp.y + Player_Pos.y;Player_RightDown.y = Player_RightDown.y + Player_Pos.yif(PossibleCollisions(Player_LeftUp, Player_RightDown, Object) ){//Make Person go in opposite direction}}

Somewhat like that. I'm in a rush so I couldn't make it 'programatically' correct. Especially with the Vectors.

Share on other sites
but lets say i had a room that looked like a pool and i started on the deck, fell into the pool and could jump back out onto the deck and it was loaded as one model, how would get it so that when the player fell he would collide with the pool part then be able to jump back up again

its weird but thats the best way i could think of to explain my question

Share on other sites
Whups. Id like to point out that those Y's in my code should be Z's.

That same method (above) can be used for colliding up or down (as ours were colliding left, right, and forward or backwards). All you do is add a Y coordinate into the problem. Or handle that a tad bit differently:

Vector3D Player_LeftUp(-2,2,-2);Vector3D Player_RightDown(2,-2,2);Vector3D PlayerPos(0,0,0);Block Object(4,8,8,4,4,8); //Left x is Ax while right x is Bx. Vice versa for Y'sVector3D ObjectPos(10,10, 0);bool PossibleCollision(Vector * PlayerA, Vector * PlayerB, Block * block){if(PlayerA.x >= block.Ax && PlayerB.x <= block.Bx && PlayerA.z <= block.Az && PlayerB.z >= block.Bz){return true;}return false;}bool InstanceAtGround(Vector * PlayerA, Vector * PlayerB, LevelFloor * block){//Same thing as above, but only check for Y's amongst the objects}void GameUpdate(){Player_LeftUp.x = Player_LeftUp.x + Player_Pos.x;Player_RightDown.x = Player_RightDown.x + Player_Pos.x;Player_LeftUp.z = Player_LeftUp.z + Player_Pos.z;Player_RightDown.z = Player_RightDown.z + Player_Pos.zPlayer_LeftUp.y = Player_LeftUp.y + Player_Pos.y;Player_Rightdown.y = Player_Rightdown.y + Player_Pos.y;if(PossibleCollisions(Player_LeftUp, Player_RightDown, Object) ){//Make Person go in opposite direction}}void PlayerFall(){if(!InstanceAtGround() ){Player.y += GAME_GRAVITY;}}

1. 1
2. 2
Rutin
15
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• Forum Statistics

• Total Topics
633733
• Total Posts
3013585
×