I am looking for any helpful information on implementing the arrive steering behavior. Following along the psuedocode in a book to do it, but cannot figure out how to implement it in C++. So far I have this much figured out:
//implements the arrive steering behavior
//steering.linear represents direction
void Steering::Arrive( sf::Vector2f position, sf::Vector2f target, float maxAcceleration, float maxSpeed, float distance, float targetRadius, float slowRadius, float timeToTarget, SteeringOutput& steering )
{
timeToTarget = 0.1;
//get the direction to the target
steering.linear = target - position;
distance = (steering.linear).length();
//check if object has arrived to destination
if(distance < target.radius) {
return;
}
//if outside the slow radius, go max speed
if(distance > slowRadius) {
target.speed = maxSpeed;
}
//calculate a scaled speed if inside slow radius
else {
target.speed = maxSpeed * distance / slowRadius
}
//target velocity combines speed and direction
target.velocity = steering.linear;
MathHelper::Normalize( target.velocity );
target.velocity *= target.speed;
//acceleration tries to get to the target velocity
steering.linear = target.velocity - position.velocity;
steering.linear /= timeToTarget;
//check if acceleration is too fast
if((steering.linear).length() > maxAcceleration) {
MathHelper::Normalize( steering.linear );
steering.linear *= maxAcceleration;
}
}
A lot of this is my interpretation of the psuedocode from the book. What would I need to change or add to actually implement it to be ran as a program?