Computer Science Canada Need help with collision detection |
Author: | JavaMan [ Fri Dec 07, 2012 1:50 pm ] | ||||
Post subject: | Need help with collision detection | ||||
Can someone help me with my collision detection in my game:
I cant figure out how to get collision detection for the blocker to work properly. Mod Edit: Pleas wrap you code in either of the following in order to preserve whitespace (indentation) and to highlight the syntax.
|
Author: | Zren [ Fri Dec 07, 2012 9:56 pm ] | ||||
Post subject: | RE:Need help with collision detection | ||||
When you punch a wall, your hand doesn't go through the wall, then magically be set outside of it. Instead, you don't even reach where your hand would be if it remained at the same velocity. Right now, you're moving the (x,y) coordinates during your input stage. Instead hold off until reaching the logic stage. Due to which, you try to set the player outside of the object in a specific position. Exhibit A: A general game engine loop.
Basically you should only change the velocity during the input stage, then later check where the entity will end up first. If it will end up somewhere it doesn't collide with anything, you can move it there. Example:
Note that this method is also flawed, but this should help get the ball rolling. |