CharacterControl and multiple enemies

Hello,

I’m making a simple “zombie” enemy for my game. It uses 2 functions: MakeZombie (to create it) and ZombieRoutine (to update it).

I make the zombie a CharacterControl object. It seems to work fine for one monster.

If I try to run makeEnemy more than once, I get multiple enemies on screen, but only one of then moves.



Is there anyway I can make zombieRoutine access the right zombies?

Furthermore, is there anyway I can generate zombies automatically like “zombie1”,“zombie2” and so on?



The code:

[java] private void makeEnemy(Vector3f loc) {

CapsuleCollisionShape zombieCapsule = new CapsuleCollisionShape(1.5f, 6f, 1);

zombie = new CharacterControl(zombieCapsule, 0.05f);

mzombie = (Node) assetManager.loadModel(“Models/Oto/Oto.mesh.xml”);

mzombie.setLocalScale(0.5f);

mzombie.addControl(zombie);





bulletAppState.getPhysicsSpace().add(zombie);

zombie.setPhysicsLocation(loc);

rootNode.attachChild(mzombie);



}[/java]

[java] private void zombieRoutine(){

Vector3f spd = ppl.getPosition().subtract(mzombie.getLocalTranslation());



zombiewalk =new Vector3f(0,0,0.1f);

if(spd.length()<=battery/4) zombiewalk =new Vector3f(0,0,0.01f);

Vector3f sub = model.getLocalTranslation().subtract(mzombie.getLocalTranslation());

if(sub.length()<30f){

if(character.getPhysicsLocation().z > zombie.getPhysicsLocation().z ){

zombie.setWalkDirection(zombiewalk);}

else{

zombie.setWalkDirection(zombiewalk.negate());}



}else{

zombiewalk =new Vector3f(0,0,0);

zombie.setWalkDirection(zombiewalk);

}

}[/java]



Thanks in advance :slight_smile:

Add this stuff to a list and then call the zombieRoutine() for each element in the list. I’m going to get around to posting the code for something like this eventually but that’s basically how I did it. The real problem is that the CharacterControls don’t seem to want to collide with each other.