Yo. Im writting a game in which player is shotting with computer bots. I have done movement player and collisions with "right" set wall rotation(0,90,180,270,360). But if change rotation of wall then algorithm for SAT doesnt work good like this on ss:
Work good:
And dont work good:
So if you saw, if i changed rotation then sat doesnt works good ;/ This algorithm isnt main. I get this form this film:
and code looks like this:
bool Player::Sat(const Sprite &sp1, const Sprite &sp2, Vector2f *out_mtv)
{ const FloatRect &rectSp1 = sp1.getGlobalBounds();
const FloatRect &rectSp2 = sp2.getGlobalBounds();
float proj_x, proj_y, overlap_x, overlap_y;
// test overlap in x axis
proj_x = max(rectSp1.left + rectSp1.width, rectSp2.left + rectSp2.width) - min(rectSp1.left, rectSp2.left);
if (proj_x < rectSp1.width + rectSp2.width) {
if (out_mtv) {
// calculate mtv in x
overlap_x = rectSp1.width + rectSp2.width - proj_x;
}
// test overlap in y axis
proj_y = max(rectSp1.top + rectSp1.height, rectSp2.top + rectSp2.height) - min(rectSp1.top, rectSp2.top);
if (proj_y < rectSp1.height + rectSp2.height)
{
if (out_mtv)
{
// calculate mtv in y
overlap_y = rectSp1.height + rectSp2.height - proj_y;
out_mtv->x = out_mtv->y = 0;
// choose minimun overlap
if (overlap_x < overlap_y) {
out_mtv->x = overlap_x * (rectSp1.left < rectSp2.left ? -1 : 1);
}
else {
out_mtv->y = overlap_y * (rectSp1.top < rectSp2.top ? -1 : 1);
}
}
return true;
}
}
return false;
}
Im writing in sfml like 5 days and sat algorithm is too difficult ;/ Can you give me hint how i have change this code to get the perfect sat algorithm? I know i have to use .getTransform but its a bit difficult for me ;d