How can I make the view follow the player entity when it's nearly out of the drone's (the view) view.
I have here my code for the drone's movement.
void World::update(const sf::Time& deltaTime)
{
mSceneGraph.update(deltaTime);
mDrone.setCenter(mPlayer->getPosition());
}
What I want to achieve is to make the drone follow the player, but not really following the player's new position as it moves real-time. Instead, the drone will SMOOTHLY MOVE if the player is NEARLY OUT OF VIEW (not hitting the view's boundary).
Right now you are just setting the view's center to be the same position as the player every update. You just need to change that to only setting the view's center if the player is farther away from the center than you want.
For example, here is one way you could handle it
playerBoundary = 100
if (mPlayer->getPosition().x > mDrone.getCenter().x + playerBoundary)
{
newViewCenter = {mPlayer->getPosition().x - playerBoundary, mDrone.getCenter().y}
mDrone.setCenter(newViewCenter);
}
This would handle the player moving too far to the right. Just repeat something similar for the other 3 directions.