Help to create enemy NPC

I need to create an enemy, and i don’t know what is the recommend way to do that, if is creating a class to implement Control, a class to extends AbstractPhysicsControl. Can someone explain it to me?

It’s really going to depend on your game but there is a tutorial on this under the advanced section of the tutorials.

Here’s the link to the main tutorial I’m talking about:
But more specific to your question:

Hey, can you explain me the usage of AbstractControl and AbstractPhysicsControl. I want to create a enemy with a behavior similar with goomba of mario bros.

Hi there,

When I made an an enemy character. I gave him a character control.

With the character control you can set move direction. So if you want him to walk back and forth or follow the player you can do this within the tick loop.

Here’s how I did it. The first link is my MonsterManager which is an AppState. The second link is my monster class, which extends node.

Take a look and it should help you with creating an npc, who can act on distance.

But I don’t have an AI

It probably will work, thanks, I thought CharacterControl was only for create player.

At the start it is working good, but i need to know how can I ignore the colision with ground?

It may be better if you explain what you’re trying to achieve overall.

i want to create a NPC with behavior similiar to goomba in mario, moving for the left side, when it colides with object or wall, it changes your direction.

okie dokie that’s easy enough my friend!

You can use the model bound to collide with certain objects in the scene. Simply attach the objects in the scene like walls or other creatures, to a node.

Then on the tick loop, check to see if the any of your “goombas” models are colliding with your objects in the other node. If so, have it change direction

Node wallNode = someNodeWithAllPossibleCollisions;
CollisionResults results = new CollisionResults();
wallNode.collideWith(player.model.getWorldBound(), results);

if(results.size() > 0){

// switch direction stuff here

Should be something similar to what your looking for, and if your results size is more 0 that means your goomba model is hitting something.

For multiple goombas have a goombaList or goombaNode and to a for each, and check if any of them are colliding.

And you should have a working list of things knowing what they’re hitting

Thanks for the help, I had a nice idea that is to put ground in one model, and all other objects in others models, set the name of the ground model, implement PhysicsCollisionListener in my NPC and check if the collision happens with objects that doesn’t has the ground name (is not the ground), it works perfectly, thanks alot for all help.

1 Like