Explanation
I have a rectangle with a trigger on it when it's hit by my player game object from the side it's supposed to activate a certain method. Illustration:
And when it's hit from the bottom or top it's supposed to activate an other method. Illustration:
However the way I'm checking what method to use is not working in all cases.
Problem
There are some cases where the player is hitting the side of the rectangle but the method being called is the one supposed to be called when the rectangle is hit from the bottom or the top. When the player is hitting the top or bottom everything is working just fine.
Code
protected override void OnCollision(Collider2D coll, PlayerMovement player)
{
float playerMaxY = player.YCord + player.Height / 2;
float playerMinY = player.YCord - player.Height / 2;
//YCord is the y coordinate of the rectangle
float thisMaxY = YCord + Height / 2;
float thisMinY = YCord - Height / 2;
base.OnCollision(coll, player);
//This condition here is where i need an improvement
if ((playerMinY >= thisMaxY && playerMaxY >= thisMaxY) ||
(playerMinY >= thisMinY && playerMaxY >= thisMinY))
BounceHorizontal(coll, player);
else
BounceVertical(coll, player);
}