Walking Along Path - Terasology/TutorialPathfinding GitHub Wiki
MoveToAction
This is the behavior node that makes a character move from the current position to the target position as stored in the character's MinioMove component.
private boolean processDirect(Actor actor, MinionMoveComponent moveComponent) {
LocationComponent locationComponent = actor.getComponent(LocationComponent.class);
boolean reachedTarget = false;
Vector3f worldPos = new Vector3f(locationComponent.getWorldPosition());
Vector3f targetDirection = new Vector3f();
targetDirection.sub(moveComponent.target, worldPos);
Vector3f drive = new Vector3f();
float yaw = (float) Math.atan2(targetDirection.x, targetDirection.z);
float requestedYaw = 180f + yaw * TeraMath.RAD_TO_DEG;
if( targetDirection.lengthSquared() < distanceSquared) {
drive.set(0, 0, 0);
reachedTarget = true;
} else {
targetDirection.normalize();
drive.set(targetDirection);
}
CharacterMoveInputEvent wantedInput = new CharacterMoveInputEvent(0, 0, requestedYaw, drive, false, false, moveComponent.jumpMode, (long) (actor.getDelta() * 1000));
actor.getEntity().send(wantedInput);
return reachedTarget;
}
It has a processDirect function that makes a beeline to the target position. If it gets stuck, it starts jumping up in an effort to try and get itself unstuck.
MoveAlongPathNode
This is a decorator node that iteratively sets the child's MinionMoveComponent's target to the next point in the path. It is used when the paths are complex with many path segments. It is used in conjunction with a move_to node (described above) as so:
` sequence: [`
`set_target_to_followed_entity,`
`find_path,`
`{`
`move_along_path: {`
`child: {`
`move_to: {}`
`}`
`}`
`}`
`]`
This node returns success only on the successful completion of all the segments of the path.