Unexperienced guy - collision detection, help needed :)

Started by
3 comments, last by fng 13 years, 3 months ago
Hey guys!
I'm new to this forum, I hope I opened the thread in the right sub-forum, sorry if I didn't.

Ok, so.. I have no experience with physics or anything, I am coding an addon to an already existing game.
I am done with the addon and everything is working great, I have only one thing left - collision detection.
the game, obviously detect the collisions but my addon, as a seperate program doesn't.
the game is a 2D game so the collisions has X & Y only, the obstacles aren't circular,
and I have a list of the all obstacles (Top-Right X & Y, Top-Left X & Y, Bottom-Right X & Y and Bottom-Left X & Y)

It isn't THAT IMPORTANT but I do want things to be 100% complete so I came over here to ask for a little help.

Ok, let's get to the point =)
I don't need to detect collisions on real-time, I only need to find out if there will be a collision on movement.
I know I usually don't explain myself so good so I used my "awesome" paint skills =P, here's what I mean:

Picutre #1:
47907715.gif
(http://img163.images...57/47907715.gif)

Picture #2
49455598.gif
(http://img15.imagesh...88/49455598.gif)

Map Legend:
Green = start point (the player&#39;s current location).<br /> Purple = endpoint location (the endpoint that the player WANT to get to).<br /> Brown = actual endpoint location (the endpoint that the player got to).<br /> Blue = the full waypoint from the player&#39;s location to the endpoint.<br /> Red = obstacle objects.<br /> <br /> On picture #1 the player want to move from 1,3 to 24,26 and he successfully gets to 24,26 because there is no collision.<br /> on picture #2 the player want to move from 2,1 to 21,20 but he actually go to 16,15 because there&#39;s a collision at this location.<br /> <br /> So.. what I want to find out is a possible collision BEFORE the player actually moves.<br /> for example, if I want to go from 2,1 to 21,20 (as in the 2nd picture), how can I check if there will be a collision?<br /> damn, I am really bad at explaining myself, I really hope you understand me, the collisions aren&#39;t in real-time, I just need to know if there WILL BE a collision.<br /> also, is there any way to find out where the player will &quot;stop&quot;, as in the 2nd picture, where the player&#39;s movement were actually from 2,1 to 16,15 instead of 21,20.<br /> <br /> I really hope you understood me <img src='http://public.gamedev.net/public/style_emoticons/<#EMO_DIR#>/unsure.gif' class='bbc_emoticon' alt=':unsure:' /><br /> <span style="font-weight:bold;">here&#39;s some additional information in case it means anything:</span><br /> I have all of the obstacles&#39; coordinates (again).<br /> I have the player&#39;s current coordinates.<br /> I have the player&#39;s endpoint coordinates (the location he want to go to).<br /> I have the player&#39;s angle before and after the movement.<br /> I am coding with VB.Net if it means anything, but I don&#39;t think it does.. I only want a &quot;mathematical&quot; (or whatever it is) way to do this thing =)<br /> <br /> Thanks a lot guys&#33; <img src='http://public.gamedev.net/public/style_emoticons/<#EMO_DIR#>/smile.gif' class='bbc_emoticon' alt=':)' /> and sorry about my lame English.<br /> <br /> <span style="font-weight:bold;">P.S</span><br /> I&#39;ve been searching for like 4 days now, I just got way too confused with everything I have read lately.<br /> this is why I posted here.. and I know this is a lot more easier than a real-time collision detection.<br /> I am just too unfamiliar with the whole thing to point out what I need from all of the things I did find.<br /> so please don&#39;t yell at me &quot;use the search&quot; etc, I am way too confused with the whole thing <img src='http://public.gamedev.net/public/style_emoticons/<#EMO_DIR#>/sad.gif' class='bbc_emoticon' alt=':(' />
Advertisement
This sounds like a logic error in the code. You can't really 'predict' collision, it happens in real-time. It is simply the intersection of two objects. Plus, you won't always know where the player is going to move. It may just be that your add on is simply not checking collision in the right place. The collision check may be happening after everything else is calculated.

For example:


while( gameEnd != false)
{
// Game Code Here
Render();
CalcLogic();
CollisionCheck();
}



In the above case, your collision is being checked after you have already rendered to the screen and calculated the other game logic. In this case, you might find effects like characters going through each other then 'magically' bouncing away in the next frame or characters getting stuck in walls. This is obviously an exaggerated example, but I think it may be the solution to your problem. Check around your add on and make sure the collision detection is being checked in the appropriate place.

This sounds like a logic error in the code. You can't really 'predict' collision, it happens in real-time. It is simply the intersection of two objects. Plus, you won't always know where the player is going to move. It may just be that your add on is simply not checking collision in the right place. The collision check may be happening after everything else is calculated.

For example:


while( gameEnd != false)
{
// Game Code Here
Render();
CalcLogic();
CollisionCheck();
}



In the above case, your collision is being checked after you have already rendered to the screen and calculated the other game logic. In this case, you might find effects like characters going through each other then 'magically' bouncing away in the next frame or characters getting stuck in walls. This is obviously an exaggerated example, but I think it may be the solution to your problem. Check around your add on and make sure the collision detection is being checked in the appropriate place.

I'm sorry, don't want to sound too snobbish, but.. did you even read my post?
everything you wrote has nothing to do with my question.. ;)

Thanks anyways though! :)
I think I would try it like this:
Perform a* pathfinding to get the shortest path to your estimated position.
Usually a* would try another path if an obstacle was found or the square is not walkable. In your case you would strictly follow the path as if there was no obstacle, but store the information which square is the first obstacle in your path. With that way you could also differ between an obstacle and "walkable" squares.

Maybe this idea helps you... There might be a better solution, but this was the first which came to mind :)
Cheers Zerd
I would recommend to start of with a brute force method and check whether any point on the "path" is within one of the obstacles.

To speed things up you could use a 2D array of all your cells and mark them blocked just as you did in your visualization and perform the tests in there.

Does the player have some kind of bounding shape, e.g. a disc (or sphere)? If so you might run into problems as the player might not collide with an obstacle when it passes very close to a vertex.

Nice paint skills btw.

(edit: added missing full stops)
-- blog: www.fysx.org

This topic is closed to new replies.

Advertisement