# Unexperienced guy - collision detection, help needed :)

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

## Recommended Posts

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:

(http://img163.images...57/47907715.gif)

Picture #2

(http://img15.imagesh...88/49455598.gif)

Map Legend:
[color="#008000"]Green = start point (the player's current location).
[color="#9932cc"]Purple = endpoint location (the endpoint that the player WANT to get to).
[color="#a0522d"]Brown = actual endpoint location (the endpoint that the player got to).
[color="#0000ff"]Blue = the full waypoint from the player's location to the endpoint.
[color="#ff0000"]Red = obstacle objects.

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.
on picture #2 the player want to move from 2,1 to 21,20 but he actually go to 16,15 because there's a collision at this location.

So.. what I want to find out is a possible collision BEFORE the player actually moves.
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?
damn, I am really bad at explaining myself, I really hope you understand me, the collisions aren't in real-time, I just need to know if there WILL BE a collision.
also, is there any way to find out where the player will "stop", as in the 2nd picture, where the player's movement were actually from 2,1 to 16,15 instead of 21,20.

I really hope you understood me
here's some additional information in case it means anything:
I have all of the obstacles' coordinates (again).
I have the player's current coordinates.
I have the player's endpoint coordinates (the location he want to go to).
I have the player's angle before and after the movement.
I am coding with VB.Net if it means anything, but I don't think it does.. I only want a "mathematical" (or whatever it is) way to do this thing =)

Thanks a lot guys! and sorry about my lame English.

P.S
I've been searching for like 4 days now, I just got way too confused with everything I have read lately.
this is why I posted here.. and I know this is a lot more easier than a real-time collision detection.
I am just too unfamiliar with the whole thing to point out what I need from all of the things I did find.
so please don't yell at me "use the search" etc, I am way too confused with the whole thing

##### Share on other sites
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.

##### Share on other sites

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!

##### Share on other sites
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

##### Share on other sites
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) Edited by fng

1. 1
2. 2
3. 3
Rutin
15
4. 4
khawk
13
5. 5
frob
12

• 9
• 9
• 11
• 11
• 23
• ### Forum Statistics

• Total Topics
633669
• Total Posts
3013259
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!