Friday, November 25, 2022
HomeGame Developmentmotion - Arrive Steering Behaviour velocity not reducing correctly

motion – Arrive Steering Behaviour velocity not reducing correctly


I am attempting to implement the Arrive Steering Behaviour with acceleration from AI For Video games third version by Ian Millington (Algorithm on Web page 63)

operate getSteering() -> SteeringOutput:
    consequence = new SteeringOutput()

    path = goal.place - character.place
    distance = path.size()
    
    if distance < targetRadius:
        return null

    if distance > slowRadius:
       targetSpeed = maxSpeed
    else:
       targetSpeed = maxSpeed * distance / slowRadius

    targetVelocity = path
    targetVelocity.normalize()
    targetVelocity *= targetSpeed

    consequence.linear = targetVelocity - character.velocity
    consequence.linear /= timeToTarget

    if consequence.linear.size() > maxAcceleration:
        consequence.linear.normalize()
        consequence.linear *= maxAcceleration
 
    consequence.angular = 0
    return consequence

My implementation in C++ is as follows:

SteeringOutput consequence{};

Vector2D path  = target->place - character->place;
float distance      = path.getLength();

if (distance < targetRadius)
    return consequence;

float targetSpeed{};

if (distance > slowRadius)
    targetSpeed = maxSpeed;
else
    targetSpeed = maxSpeed * distance / slowRadius;

Vector2D targetVelocity = path;
targetVelocity.normalise();
targetVelocity          *= targetSpeed;

consequence.linear = targetVelocity - character->velocity;
consequence.linear /= timeToTarget;

if (consequence.linear.getLength() > maxAcceleration)
{
    consequence.linear.normalise();
    consequence.linear *= maxAcceleration;
}

consequence.angular = 0;

return consequence;

The replace rule for the characters is:

character.place.x    += character.velocity.x * time;
character.place.y    += character.velocity.y * time;

character.orientation   += character.rotation * time;

character.velocity += steering.linear  * time;
character.rotation += steering.angular * time;

if (character.velocity.getLength() > maxSpeed)
{
    character.velocity.normalise();
    character.velocity *= maxSpeed;
}

The algorithm works till the goal is meant to reach inside the goal radius.
As soon as the gap between goal and character is lower than the goal radius the rate of the character ought to be zero. Nonetheless, the character arrives inside goal radius with non-zero velocity and continues to maneuver till it reaches the goal after which oscillates just like the Search Behaviour.

I’ve tried adjusting the values to alter the behaviour however each time the character arrives with some non-zero velocity.
I’ve additionally tried to calculate the gap between the character and one level on the circle within the goal radius, and that does appear to work higher, but it surely’s nonetheless non-zero.

Another approaches contain setting the rate to zero manually as soon as the character is contained in the targetRadius, however I do not assume it is purported to be fastened that method.

Do you will have any concepts what could be mistaken ? Is there one thing lacking from the algorithm ?
Thanks upfront.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments