0
\$\begingroup\$

Assume that this behavior has Separation behavior. I tried to implement the FollowLeader behavior from this article. In the code below is my working implementation. But there is a problem, when I convert the owner linear velocity to direction (North, South, East, West), it doesn't give the proper direction to achieve the correct facing of my animation.

    protected SteeringAcceleration<T> follow(SteeringAcceleration<T> steering, Steerable<T> leader) {
        T tv = leader.getLinearVelocity().cpy();
        // calculate the ahead point
        tv.nor();
        tv.scl(LEADER_BEHIND_DIST);
        ahead = leader.getPosition().cpy().add(tv);

        // calculate the behind point
        tv.scl(-1);
        behind = leader.getPosition().cpy().add(tv);

        if(isOnLeaderSight(leader, ahead)) {
            evade.calculateSteering(steering);
            force.add(steering.linear);
        }

        arrive(steering, behind);
        force.add(steering.linear);

        // separation(..) assume exists

        steering.linear.set(force);
        steering.angular = angular;

       return steering;
    }
\$\endgroup\$
0
\$\begingroup\$

I fixed it, it's a little bit different when implementing using Gdx-ai. Here is the solution.

BlendedSteering<Vector2> followLeader = ...

followLeader.add(new ArriveBehind(owner, leader), 1f);
followLeader.add(new Evade(owner, leader). 1.5f); // tweak until matches, for me I used 1.5f

setBehavior(followLeader);

Then in the update method. Enable the evade behavior only if in the leader sight or ahead.

evade.setEnabled(isOnLeaderSight(leader, getAhead(leader)));
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.