Target speed

closed account (yR4jz8AR)
Hello everyone. 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 speed and target velocity. Can anyone help me out a bit? Here is what I have so far.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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;
	}
Last edited on
I just need the equation for target speed and target velocity.
Are you sure?

Read this:
http://www.physicsclassroom.com/class/1DKin/Lesson-1/Speed-and-Velocity
Topic archived. No new replies allowed.