Domanda

I am having trouble figuring out what the equation is to find the speed of a target. I am working with sf::Vector2f to find the arrival function in a 2D game. I just need the equation for target velocity. Can anyone help me out a bit? Here is what I have so far.

void Steering::Arrival( sf::Vector2f position, sf::Vector2f target, float maxSpeed, float maxAcceleration, float timeToTarget, float slowRadius, float targetRadius, float targetSpeed, double distance, SteeringOutput& steering ){

timeToTarget = 0.1;

steering.linear = target - position;
distance = sqrt( steering.linear.x * steering.linear.x + steering.linear.y * steering.linear.y);
targetSpeed = maxSpeed * distance / slowRadius;

//Check if arrived at target
if (distance < targetRadius)
{
    MathHelper::ZeroVector;
}

//Check if we are out of the slowRadius
if (distance > slowRadius)
{
    targetSpeed = maxSpeed;
}
else
{
    targetSpeed = maxSpeed * distance / slowRadius;
}

Thank you in advance.

È stato utile?

Soluzione

Target velocity = (unit vector from Position to Target) * (target speed). If you need some advance targeting, search for 'Kalman filter'

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top