Example usage for com.badlogic.gdx.ai.steer.behaviors FollowPath FollowPath

List of usage examples for com.badlogic.gdx.ai.steer.behaviors FollowPath FollowPath

Introduction

In this page you can find the example usage for com.badlogic.gdx.ai.steer.behaviors FollowPath FollowPath.

Prototype

public FollowPath(Steerable<T> owner, Path<T, P> path, float pathOffset) 

Source Link

Document

Creates a non-predictive FollowPath behavior for the specified owner, path and path offset.

Usage

From source file:com.mygdx.game.steerers.FollowPathSteerer.java

License:Apache License

public FollowPathSteerer(final SteerableBody steerableBody) {
    super(steerableBody);

    // At least two points are needed to construct a line path
    Array<Vector3> waypoints = new Array<Vector3>(new Vector3[] { new Vector3(), new Vector3(1, 0, 1) });
    this.linePath = new LinePath<Vector3>(waypoints, true);
    this.followPathSB = new FollowPath<Vector3, LinePath.LinePathParam>(steerableBody, linePath, 1);

    this.prioritySteering.add(followPathSB);
}

From source file:toniarts.openkeeper.world.creature.CreatureControl.java

License:Open Source License

public void navigateToRandomPoint() {
    Point p = worldState.findRandomAccessibleTile(
            worldState.getTileCoordinates(getSpatial().getWorldTranslation()), 10, creature);
    if (p != null) {
        GraphPath<TileData> outPath = worldState
                .findPath(worldState.getTileCoordinates(getSpatial().getWorldTranslation()), p, creature);

        if (outPath != null && outPath.getCount() > 1) {

            // Debug
            //                worldHandler.drawPath(new LinePath<>(pathToArray(outPath)));
            PrioritySteering<Vector2> prioritySteering = new PrioritySteering(this, 0.0001f);
            FollowPath<Vector2, LinePathParam> followPath = new FollowPath(this,
                    new LinePath<>(pathToArray(outPath), true), 2);
            followPath.setDecelerationRadius(1f);
            followPath.setArrivalTolerance(0.2f);
            prioritySteering.add(followPath);

            prioritySteering.setEnabled(!isAnimationPlaying());
            setSteeringBehavior(prioritySteering);
        }/*from  w  ww.  j  av  a2 s .  c  o  m*/
    }
}

From source file:toniarts.openkeeper.world.creature.CreatureControl.java

License:Open Source License

public void navigateToAssignedTask() {

    Vector2f loc = assignedTask.getTarget(this);
    if (loc != null) {
        GraphPath<TileData> outPath = worldState.findPath(
                worldState.getTileCoordinates(getSpatial().getWorldTranslation()),
                new Point((int) Math.floor(loc.x), (int) Math.floor(loc.y)), creature);

        if (outPath != null && outPath.getCount() > 1) {

            // Debug
            //                worldHandler.drawPath(new LinePath<>(pathToArray(outPath)));
            PrioritySteering<Vector2> prioritySteering = new PrioritySteering(this, 0.0001f);
            FollowPath<Vector2, LinePathParam> followPath = new FollowPath(this,
                    new LinePath<>(pathToArray(outPath), true), 2);
            followPath.setDecelerationRadius(1f);
            followPath.setArrivalTolerance(0.2f);
            prioritySteering.add(followPath);

            prioritySteering.setEnabled(!isAnimationPlaying());
            setSteeringBehavior(prioritySteering);
        }/*from   w w  w . j a  va  2 s .  c  om*/
    }
}