void player::collision(mob M)
{
//horizontal
if(right >= M.left && top < M.bottom && bottom > M.top && right < M.right)
{
rect.setPosition(M.left - rect.getSize().x, rect.getPosition().y);
}
if(left <= M.right && top < M.bottom && bottom > M.top && left > M.left)
{
rect.setPosition(M.right, rect.getPosition().y);
}
}
Hi, I'm trying to create a solid bounding box style collision system for my game. So far, I can tell whether or not the horizontal planes intersect, but whenever I attempt at detecting whether or not they intersect vertically, the horizontal detection overrides it no matter what order I program it in.
(Also, here are the directional variable if necessary)
void player::update()
{
bottom = rect.getPosition().y + rect.getSize().y;
left = rect.getPosition().x;
right = rect.getPosition().x + rect.getSize().x;
top = rect.getPosition().y;
}
I was wondering if someone could point me in the right direction. Thanks!