-
-
Notifications
You must be signed in to change notification settings - Fork 556
Adding AI
Almas Baimagambetov edited this page Dec 28, 2020
·
4 revisions
There are multiple ways of adding AI to your enemy entities. Whilst all are valid ways to adding AI, certain approaches are more suitable based on your use case.
The most basic AI can be added by attaching a Component
to an entity. An example of a simple "sensor" AI as follows:
public class SensorComponent extends Component {
@Override
public void onUpdate(double tpf) {
Entity player = ...
if (getEntity().distance(player) < 100) {
// constantly signal other AI that player is close
} else {
// don't signal
}
}
}
First, add StateComponent
to your entity. Next, implement your states:
private EntityState GUARD = new EntityState() {
@Override
protected void onUpdate(double tpf) {
}
};
TODO
TODO
TODO