[SOLVED] Spatials with specific Properties (userData). Interfaces?

Hey guys,

I’m playing around with a basic FPS.

I want to be able to shoot 2 types of targets:

Enemies take damage (userData “health”)

Objects get pushed away (RigidBodyControl)

Normally I would now have 2 interfaces “isDamageable” and “isPushable”.

However I would also have a “isTargetable” interface instead of a “Shootables” Node.

So I am asking here: How do I implement this the jMonkey way?

atm I have the following Nodes:

  • Shootables
    • Damageable
      • myEnemy
    • Pushable
      • myBox

        Problem: Noone can stop me from accidentially adding a Box to the Damageable group.

        And checking for the parents name on each Shot sounds like a workaround

        Thanks in Advance :smiley:

My favorite solution to this problem is using an Entity System. There are several mentions of it on the jme forum and it is on google.

Basically an entity is just an id, and it has a bunch of components associated with it. Then you have systems that look at those components. For instance the CombatSystem will look at all entities with HealthComponents and AttackComponents.

Yeah, just add HealthComponent, PushableComponent etc… for your entity system.

These components can store float/intager values.

Have a look at this example:


I think using an entity system in this case might be shooting ducks with cannons.

I’d use Controls for that. Every node that is shootable in a way is placed in the shootable node. So you can easily check if it was hit.

Then, instead of Interfaces, you use Controls, e.g. HealthControl. you can simply check if the spatial that was hit has the HealthControl, and if it has, use the HealthControl to adjust the actual health value.

Maybe you can even create a HitControl that performs logic for hits in general. I’d probably write a HitControl and let it provide the ability to register more Controls on itself. So when you add The HealthControl to the spatial it gets registered to the HitControl and automagically triggered when the object is hit. That way you could add arbitrary behavior on hits without modifying the HitControl each time.

Don’t get me wrong - ES are a great approach, but they can be tricky, and for a simle FPS using an ES can be overkill.

1 Like

agree with polygnome.

Entity System is too advanced for simple project such basic FPS.

and everything can be done with Controls here.

I agree that an entity system is a lot to take on if you don’t already know how to roll one… but I think it’s entirely appropriate for an FPS.

But the others are right, have a control for the targetable stuff and a control for the damageable stuff, etc… Don’t use the scene graph hierarchy for this and don’t extend node/spatial for this. This is kind of what controls are for.