Skip to content

Adding AI

Almas Baimagambetov edited this page Jul 14, 2017 · 4 revisions

There are multiple ways of adding AI to your enemy entities.

Control (ECS)

The most basic AI can be added by attaching a Control to an entity. An example of a simple "sensor" AI as follows:

class SensorControl extends Control {
    @Override
    public void onUpdate(Entity entity, double tpf) {
        Entity player = FXGL.getApp().getGameWorld() ...
        if (distanceToPlayer(player) < 100) {
            // constantly signal other AI that player is close
        } else {
            // stop signalling
        }
    }

    private double distanceToPlayer(Entity player) {
        return player.getComponent(PositionComponent.class).distance(getEntity().getComponent(PositionComponent.class));
    }
}

Behavior Tree

TODO

Goal Oriented Action Planning (GOAP)

TODO

Clone this wiki locally