Hey everyone!
I am having an issue getting the object to move to a point on the map. I have dealt with this before but for some reason I am unable to get this to work correctly using a very simple codebase.
Here is the code:
//in main
object.setPosition(25, 600);
cordinates.x = 250;
cordinates.y = 0;
//function that is called
if(object.object.getPosition().x == cordinates.x && object.object.getPosition().y == cordinates.y)
{
return true;
}
else
{
sf::Vector2f _tempPos = object.getPosition();
sf::Vector2f _targetPos = cordinates;
float dx = _targetPos.x - _tempPos.x;
float dy = _targetPos.y - _tempPos.y;
float angle = atan2(dx, dy);
float directionX = cos(angle);
float directionY = sin(angle);
object.move({directionX, directionY});
}
As the character moves he moves down and to the right instead of up and to the right but from what I have read in examples and etc. I believe to have the write code...but obviously I do not.
Thanks for the help guys