Hello everyone!
So, I have a problem thats been bugging me for 2 days now. I just cant seem to solve it. And I believe I will have to waste another 2 days if you dont help me.
So, lets say I have a player and a block. Now, I know how to find out if the player collided with the block. I just dont know on which side. I have to know if the player collided on the upper side, left side, right side or down side. But I just cant figure out how.
Recenlty, I have had a function called InRect(x, y, rect) that checked if point x,y is in the specified rectangle. Lets say the player has 4 points. Like this:
Point 1 is upper-left, point 2 is upper-right, etc.
I checked if the player fell on the block like this:
pseudo-code:
// 1 specifys x,y of the players upper-left etc.
if ( (InRect(3, rect) || InRect(4, rect)) && !(InRect(1, rect) || InRect(2, rect)))
{
return COLLIDED_DOWN_SIDE;
}
I need to check that 1 and 2 arent colliding because 1 would be true if the player collided from the left and 2 if he collided from the right...
Now this all seems well and fine but it doesent work. I beg you to help me! Is there an error in my code? Or is my method just stupid? Please, tell me, suggest something! End my pain! I would be very grateful! You can write your own techniques how you would do it...
Thank you!
Vanneto