Use Monkey Brains in Zay ES

I do like to use Monkey Brains thougether with Zay ES. But Monkey Brains use an Agent with a Spatial. How could I combine that with my Position component? Derive a own thing from Spatial and use That thing to get the new position Monkey Brains compute? Actually want those swarm stuff :grinning:
Did somebody somthing similar? Advices?

Ok more details :smile: I have invaders, at the base a space ship (similar to the old invaders game). The invaders currently are very dumb and wabble from left to right. Now I would like to add some swarming behavour to them. What I also want to implement is a smart bullet swarm like in “The 5th Element”.
My game is entirly build up with Zay ES, so a Invader consists of a Position, Model, Defend, Score, Shape. The Position component holds x, y, z and some rotation information.

I saw that Monkey Brain supports a lot of different behavour patterns, instead rewrite something by my self I would like to use that, but it seems that I need a spatial, not sure if just a simple spatial with no geometry inside or with geometry, but I think the behavour just operates with a radius => that would be my Shape. That would mean I would have to derivate my DataSpatial or something from a Spatial and handover that to the agent of Monkey Brains. And then just read the rotation/position from that spatial over time and feedback to my Entity System or more concret to the invader’s Postion component.

Or is there a better way? Or an alternative to Monkey Brains?
But thanks for listening anyway, by writting down I see some possible ways which I will now try out. But of course advices are still welcome.

If Monkey Brains is indeed tied directly to a spatial then that is unfortunate and a poor design choice on their part. If it’s true, it effectively makes monkey brains useless on a server where you likely only have game objects and no spatials at all.

It means your choices are limited. You may want to try to flag some of the monkey brains developers to see if that design assumption is really accurate or if there’s something else you haven’t seen. I’ve never looked at it so can’t comment one way or the other.

Hey thanks a lot. Ok I moved this question into the monkeybrains category, let’s see if somebody can help :smile:
I will try to digg into that code, but as far I can see it depends on an agent and the agent do contain a spatial. So separation of data and visualisation is not given.

But maybe there is some possibibilty I didn not see so far…

I don’t know how closely they watch the forums. You may have to @ mention them to get their attention.

ah ok. then I have to find out there login names. and then place that mention…

@Pesegato: I saw you as a member of monkeybrains. maybe you can help me?

It is not that much code and even the basic move behavour do stuff like this:

         agent.getSpatial().move(moveDirection.mult(agent.getMoveSpeed() * tpf));

It seems to be tightly coupled with spatials. So the only solution I see here is that

public class DataSpatial extends Spatial {
    //...
}

and use that spatial with the behavour in a system and port the position back to my ES into my Position component of my models. There is no other way, or I don’t see any, except looking for an alternative :frowning:

Sorry, I don’t use Zay ES. But I suggest to get in touch of @methusalah, as he is doing more or less the same thing.

Note: the issue is not really Zay-ES… it’s that the Monkey Brains library seems to want to treat spatials as game objects. Kind of bad part of the design I guess that rules out the library for a whole lot of use-cases (ie: any game using best practices).

But I don’t know who runs that part of the Monkey Brains project. Would be better all around if it abstracted that piece away somehow.

I agree with you.

I do: @Tihomir is the man. He made some nice but, as you pointed out, the library could use some improvements.

Hi !

I use GDX-AI which have a good behavior tree implementation, among lot of other cool AI stuffs.

You can create your tree in text files with indentation. It’s not very practical but provide a fast way to test things, and is easily enhancable. An exemple :

# tree
root
  selector
    sequence
      isEnemyRecorded
      selector
        sequence
          isEnemyDead
          forgetEnemy
        sequence
          isLowLife
          persister duration:3000 range:1000
            flee
          forgetEnemy
        sequence
            ...

You manage your entities very simply with a unique processor (system). Here is mine :

public class BehaviorTreeProc extends Processor {
	HashMap<EntityId, BehaviorTree<ShipBlackboard>> bTrees = new HashMap<>();

	@Override
	protected void registerSets() {
		registerDefault(Sighting.class, PlanarStance.class);
	}
	
	@Override
	protected void onEntityAdded(Entity e) {
		Reader reader = null;
		try {
			reader = new FileReader("assets/data/btrees/ship.tree");
			BehaviorTreeParser<ShipBlackboard> parser = new BehaviorTreeParser<ShipBlackboard>(BehaviorTreeParser.DEBUG_NONE);
			bTrees.put(e.getId(), parser.parse(reader, new ShipBlackboard(entityData, e.getId())));
		} catch (FileNotFoundException e1) {
			e1.printStackTrace();
		} finally {
			StreamUtils.closeQuietly(reader);
		}
	}
	
	@Override
	protected void onEntityUpdated(Entity e) {
		bTrees.get(e.getId()).step();
	}
}

Then all you have to do is create a blackboard to store data, and a class for each task and decorator. In my case :

There are many ways to enhance things and my implementation is certainly not the best one.

Hope it helps

3 Likes

Well… redMonkey (the library I wrote, that’s also part of monkeybrains) is basically the same thing, since it’s also based on GDX-AI.

You replied to my post but I maybe you wanted to reply to OP? :wink:

hey many thanks for your suggestion. I will have a closer look on this library and see if it fits for my usecase :smile:

I currently did download the source from monkey brain and did some small adjustment to it. I have a DataSpatial derived directly form Spatial as an interface between my ES and the behavior steering stuff. It works more or less. The sphere wanderer, wall follower and one mor do not as they need collision method of spatial. But for just to hold position and rotation a spatial is a little overkill :wink: I know. But it works.
Actually it would be easy to change I suppose. Beside the collision stuff.

I will try in couple of next month to unite all branches that other contributors made, so there will be more freedom for programmers to use this library.

looking forward to :slight_smile: