Home Game Development libgdx – How do I implement wander conduct in GDX AI?

libgdx – How do I implement wander conduct in GDX AI?

libgdx – How do I implement wander conduct in GDX AI?


So I comply with the unique gdx-ai documentation and created 2 circles to check Steering conduct.

enter image description here
The picture exhibits arrival behaviour however I’m nonetheless fairly misplaced about how they work.

Screen class:

public void present() {
        pCircle = new ShapeRenderer();
        sCircle = new SteeringCircle(pCircle, 15, 128*5, 128, Color.BLUE);

        goal = new SteeringCircle(pCircle, 15, 128,128*3 , Color.CYAN);
        Wander<Vector2> wanderSB = new Wander<Vector2>(sCircle);
        Arrive<Vector2> arriveSB = new Arrive<Vector2>(sCircle, goal).setTimeToTarget(0.1f).setArrivalTolerance(10f).setDecelerationRadius(25f);


    public void render(float delta) {

        Gdx.gl.glClearColor(63 / 255f, 128 / 255f, 70 / 255f, 1);






        mBatch.draw(img, 128, 0);



SteeringCircle class:

   public SteeringCircle(ShapeRenderer circle ,float boundingRadius, float x, float y, Color coloration) {
        pCircle = circle;
        mColor = coloration;
        this.place = newVector();
        this.place.x = x;
        this.place.y = y;
        this.boundingRadius = boundingRadius;
        this.maxLinearSpeed = 50;
        this.maxLinearAcceleration = 5000;
        this.linearVelocity = new Vector2(15,15);
        this.maxAngularSpeed = 30;
        this.maxLinearAcceleration = 5;

        this.tagged = false;

        this.steeringOutput = new SteeringAcceleration<Vector2>(new Vector2());


    public Location<Vector2> newLocation() {

        return null;

public void replace (float delta) {
        if (steeringBehavior != null) {
            // Calculate steering acceleration

            // Apply steering acceleration to maneuver this agent
            applySteering(steeringOutput, delta);

    non-public void applySteering (SteeringAcceleration<Vector2> steering, float time) {
        // Update place and linear velocity. Velocity is trimmed to most pace
        this.place.mulAdd(linearVelocity, time);
        this.linearVelocity.mulAdd(steering.linear, time).restrict(this.getMaxLinearSpeed());

        // Update orientation and angular velocity
        if (independentFacing) {
            this.orientation += angularVelocity * time;
            this.angularVelocity += steering.angular * time;
        } else {
            // For non-independent going through we now have to align orientation to linear velocity
            float newOrientation = calculateOrientationFromLinearVelocity(this);
            if (newOrientation != this.orientation) {
                this.angularVelocity = (newOrientation - this.orientation) * time;
                this.orientation = newOrientation;
  1. For the arrival behaviour, the blue circle will transfer from the unique place in the direction of the Cyan circle and comes again to the circle backwards and forwards. I assumed the blue circle is meant to cease when arriving the cyan circle which it did not. How can I make it cease at arrival? what’s mistaken with the codes?

  2. For the wander behaviour, the blue circle simply strikes north-east route and by no means goes again to the cyan circle. I assumed it would wander round however it did not. Any recommendation on what is required to alter to make the wander behaviour occurs?

Also, does anybody know what ought to Location returns? Isn’t Vector2 place already has the situation?



Please enter your comment!
Please enter your name here