Skip to main content
gamedev.net
🔒 Locked

Need help with coll. detection

Started by GDRaoul Dec 1, 2001 at 8:30 AM 0 replies 250+ views
Original Post
GDRaoul
GDRaoul
Here is my problem. We have a 3D game where we read our map from a textfile. We store that map in a array map[][]. Where: 0 = wall, 1 = floor and 2 = grass. We check for collision with the next function, the collision reaction is going back to the oldPosition (resetPos). This code work fine for the largest part of the wall, but it seems to be a bit sloppy. Because at most corners it doesn''t work. We have tried a lot of things but we can''t get it to work. Our guess is that it''s a rounding error, but we can''t get it to work. Can someone plz help us. You can contact me at Raoul23@lycos.nl for the entire projet (visualC++). Thanks in advance, greetings Raoul Our function: void CollisionCheck() // Collision Detection { bool o = 0, r = 0, u = 0, l = 0;// Boolean Values For Map Check // Variables Holding Player''s Position float xPosPlayer = thePlayer.GetXPos() float zPosPlayer = thePlayer.GetZPos(); if(map[(int)zPosPlayer / 2 - 1][(int)xPosPlayer / 2] == 0) o = 1; if(map[(int)zPosPlayer / 2][(int)xPosPlayer/2 + 1] == 0) r = 1; if(map[(int)zPosPlayer / 2 + 1][(int)xPosPlayer / 2] == 0) u = 1; if(map[(int)zPosPlayer / 2][(int)xPosPlayer / 2 - 1] == 0) l = 1; if(o && zPosPlayer < (float)((int)(zPosPlayer / 2 - 1) * 2) + 2.2f) thePlayer.ResetZPos(); if(r && xPosPlayer > (float)((int)(xPosPlayer / 2 + 1) * 2) - 1.2f) thePlayer.ResetXPos(); if(u && zPosPlayer > (float)((int)(zPosPlayer / 2 + 1) * 2) - 1.2f) thePlayer.ResetZPos(); if(l && xPosPlayer < (float)((int)(xPosPlayer / 2 - 1) * 2) + 2.2f) thePlayer.ResetXPos(); }

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.