In this fragment of my code, that i posted below i expect to make the object stop moving in one direction, but let him to move in other directions. Like this:
But the outcome is that they colide, because of getGlobalBounds, but i can move my object freely in every direction and through second object.
I have this in code: playerPosition.x + 60 to move x point to the end of x axis of the object, but i think it does nothing.
And when i change equality sign "==" to not equal it forbid me from entering the object from both sides, and when i enter from back side it slowly move me towards -x till it push me out from object.
What is wrong with this code?
Vector2f playerPosition;
Vector2f enemyPosition;
playerPosition = playerS.getPosition();
enemyPosition = enemy1S.getPosition();
if(playerS.getGlobalBounds().intersects(enemy1S.getGlobalBounds())) {
playerS.setColor(Color(255, 80, 0, 200));
if((playerPosition.x + 60) == (enemyPosition.x)) playerSpeedVector.x = -10;
}
else playerS.setColor(Color(255, 255, 255));
playerS.move(playerSpeedVector * time.asSeconds());
heroMoveClock.restart();