While debugging my code, I noticed that my getter functions are not working. And by not working, I mean they are not updating the new value of the member variable, but instead return the initialized value from constructor.
sf::Vector2f SteeringBehaviors::Seek(const sf::Vector2f targetPos)
{
sf::Vector2f agentPos = agent.getPosition(); // <-- Same problem here with agent.getPosition().
sf::Vector2f GetNormalized;
GetNormalized.x = targetPos.x - agent.getPosition().x;
GetNormalized.y = targetPos.y - agent.getPosition().y;
sf::Vector2f DesiredVelocity = NormalizeVector(GetNormalized) * agent.getMaxSpeed();
//cout << agent.getVelocity().x << " " << agent.getVelocity().y << endl; <-- Returns Zero
return (DesiredVelocity - agent.getVelocity()); //<--- agent.getVelocity() is the problem. It keeps returning zero, despite the velocity changing in the Agent update function
}
Note:
m_Velocity is a member variable from the base class MovingEntity (protected), but is being initialized in its derived class Agent (Fifth argument in the Agent ctor).
Can somebody give me a hint in what I'm doing wrong. Feel free to ask for more code if the above code is not sufficient.
Yes, the program actually enters the Update function. I even placed an output statement and it works. The problem is the getter functions not updating their new values.
The Seek function is being called in the FollowPath function which is called in the Agent Update function.
in say, the Seek function, the values do not change. Which is odd, as I said before, the Seek function is called by the FollowPath function and FollowPath is being called by the Agent Update function and Agent Update is called in the Main function.