Java 转向行为:到达行为问题

Java 转向行为:到达行为问题,java,android,game-ai,Java,Android,Game Ai,我正在我的一个OpenGL Android项目中实现引导行为,但我在理解为什么我的行为代码没有表现出应有的行为方面有点困难 在更新循环过程中,我的程序计算一个转向力,用来更新移动代理的位置。目前,它的行为与寻道行为相同,因为它会移动到Targetpos中定义的位置,但它不会像应该的那样在接近点时减速和停止,而是不断向前移动并一次又一次地超越目标 在此方面的任何帮助都将不胜感激,下面是应该为代理返回正确方向力的代码 减速只是一个1-3的枚举,编码代理应减速的不同速率 private Vector2

我正在我的一个OpenGL Android项目中实现引导行为,但我在理解为什么我的行为代码没有表现出应有的行为方面有点困难

在更新循环过程中,我的程序计算一个转向力,用来更新移动代理的位置。目前,它的行为与寻道行为相同,因为它会移动到Targetpos中定义的位置,但它不会像应该的那样在接近点时减速和停止,而是不断向前移动并一次又一次地超越目标

在此方面的任何帮助都将不胜感激,下面是应该为代理返回正确方向力的代码

减速只是一个1-3的枚举,编码代理应减速的不同速率

private Vector2 Arrive(Vector2 Targetpos, Deceleration deceleration) {
        Vector2 ToTarget = sub(Targetpos, agentPos);

        //calculate the distance to the target
        float dist = ToTarget.len();

        if (dist > 0.2f) {

            final float DecelerationTweaker = 0.3f;

            //calculate the speed required to reach the target given the desired
            //deceleration
            float speed = dist / ((float) deceleration.value() * DecelerationTweaker);

            //make sure the velocity does not exceed the max
            speed = Math.min(speed, agentMaxSpeed);

            Vector2 DesiredVelocity = mul(ToTarget, speed / dist);

            return sub(DesiredVelocity, agentVelocity);
        }

        return new Vector2(0, 0);
    }

以一定的速度以一定的距离起步,并使用给定的减速度,在目标之前或之后,都会产生一种确定的行为,直至停止。你必须计算出准确到达某一点的减速度。