SFML community forums
Help => General => Topic started by: Elit3d on August 21, 2018, 10:45:07 pm
-
My player currently has a simple collision on it that works very well for my game
if ((*charIter)->sprite.getGlobalBounds().intersects(obj.rect))
but I am going to be including AI and I need a checker to see if it can move a certain direction, if it can't it won't try to move there. Not sure where to start, so if anyone can suggest something, id greatly appriciate it
-
You can make a function that does the same check on where the sprite is going to be instead of where it is. Pass the predicted coordinates to it like so:
bool can_I_go_there(sf::FloatRect FR) { if (FR.intersects(obj.rect)) { return true; } else { return false; } }
However, this is not exactly the ideal way to have pathfinding in your game. You should look into proper pathfinding implementations.