You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
AI via Component (AI has 1 or 2 simple behaviors)
The most basic AI can be added by attaching a Component to an entity. An example of a simple "sensor" AI as follows:
publicclassSensorComponentextendsComponent {
@OverridepublicvoidonUpdate(doubletpf) {
Entityplayer = ...
if (getEntity().distance(player) < 100) {
// constantly signal other AI that player is close
} else {
// don't signal
}
}
}
AI via StateComponent (AI has 3+ different states)
First, add StateComponent to your entity. Next, implement your states: