How to detect collision direction?
BlitzMax Forums/BlitzMax Beginners Area/How to detect collision direction?
| ||
How do I detect from which direction 2 sprites collide? The problem is: My player moves 32 pixels each time, so my sprites just overlap or they don't. There's no 1 pixel collision or so. Until now my idea is to save the direction the player last moved. Something like: If Key_Down(KEY_UP) then Player._DIRECTION = _UP End If and check this within my enemy. Type TEnemy Method OnCollision() Select Player._DIRECTION Case _UP // Move TEnemy up a tile Case _DOWN // Move TEnemy down a tile End Select End Method End Type Is this a/the right way? Or do you have other suggestions? |
| ||
When you detect a collision you could just use Atan2() to calculate the vector between Sprite A and Sprite B. |