Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / 2D Collision detection response problem

Author
Message
darknut
18
Years of Service
User Offline
Joined: 25th May 2006
Location:
Posted: 1st Aug 2007 19:04
I'm having trouble with 2D collision detection. My trouble isn't detecting a collision but doing something after a collision has been detected. I'm trying to keep the player from passing thru the other character but when they collide my player gets stuck. He can move the direction backwards that he came from when colliding but he can't move the perpendicular directions. For example if you run the player into the right side of the other character you can't move up or down you have to move left to get unstuck. I store the map and player positions after each frame and when I detect a collision I move the player back to the last position but something isn't working. My tile collision is working great but I'm having so much trouble with sprites. If anyone could take a look at my code below and offer any help it would be most appreciated. I searched collision detection in the forums but couldn't find anything useful. Thanks.

Esther
17
Years of Service
User Offline
Joined: 3rd Aug 2007
Location:
Posted: 3rd Aug 2007 21:04
the variables in the first function are not recognised by the second one.
OldX1 for example is always 0 in the second function.

remember that each function has its own unique variables.


maybe thats the problem.
darknut
18
Years of Service
User Offline
Joined: 25th May 2006
Location:
Posted: 4th Aug 2007 18:41
Actually I declared those variables global outside of the functions so the functions are getting the correct values. Thank you for your help though. I'm still very much stuck on this and I can't seem to find anything on collision detection that will help me. All the articles and tutorials I find are just about detecting collisions and don't cover how to handle them when they are detected. Can anyone recommend any good articles or tutorials?
Prosaic
18
Years of Service
User Offline
Joined: 5th Aug 2006
Location: Athens
Posted: 6th Aug 2007 00:18 Edited at: 6th Aug 2007 00:20
Ok first thing that comes in mind is the coordinates offset.For better detection , the sprites position should reffer to its middle position.

I assume you call the restore function before changeing the sprites position.

Login to post a reply

Server time is: 2024-11-25 13:22:59
Your offset time is: 2024-11-25 13:22:59