AI units

I'm wondering, … what is the best approach to attach and control enemy units in jME.



I notice there is some Entity class in the library, but it's not a Node/Spatial class.



I know how I would do this in a 2D game…



Should I create something like a EntityNode class, that extends Node, and contains the location of the entity?



Just need to know the direction… :}

There are several ways to do it. I don't really like extending node for entities since it exposes too much unneccecary methods from the node class which could be easily wrapped in more controlled faishion within your entity class.

I prefer something like:

public class Entity {
      protected Node node;
      protected float height;
     
      public void setPosition(float x, float y){
            node.getLocalTranslation().set(x, height, y);
      }
      //...
}



For enemy entities, you would probably want to use a queue for tasks/commands and execute them as necessary. This also allows you to add movement paths from your pathfinder algorithm without much trouble.

I think it makes sense to extend spatials: I added a reference to my controller object to the spatial. Now when I pick an object or when I have a (relevant) collision, I can simply use that reference to influence the controller. This way I can use the MVC pattern, which is really nice  :slight_smile:

edit:

The PAC architecture for actors http://www1.acm.org/sigs/sigchi/chi97/proceedings/paper/jcc.htm#U14