targetSpeed, targetVelocity Arrival function

targetSpeed, targetVelocity Arrival function

本文关键字:function Arrival targetVelocity targetSpeed      更新时间:2023-10-16

我很难弄清楚找到目标速度的方程式是什么。我正在使用sf::Vector2f来查找2D游戏中的到达函数。我只需要目标速度的方程式。有人能帮我一下吗?这是我迄今为止所拥有的。

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;
}

提前谢谢。

目标速度=(从位置到目标的单位矢量)*(目标速度)。如果您需要一些预先定位,请搜索"卡尔曼滤波器"