Hey, I have an enemy class
class Enemy extends Node {
AnimComposer animComposer;
long lastAttack = System.currentTimeMillis(); //Time of last attack
long lastHit = System.currentTimeMillis(); //Time of last hit taken
int health = 5;
Spatial model;
Ray ray;
boolean isYellow = false; //Enemy flashes yellow when it attacks
boolean isCyan = false; //Enemy flashes green when it is hit
String action = "walk";
int idleTimer = 0;
//Enemy Constructor
public Enemy(Vector3f pos) {
setLocalTranslation(pos);
createModel();
Spatial probeHolder = assetManager.loadModel("/assets/Models/Sky_Cloudy.j3o");
LightProbe probe = (LightProbe)probeHolder.getLocalLightList().get(0);
probe.setPosition(Vector3f.ZERO);
probeHolder.removeLight(probe);
addLight(probe);
setName("enemy"+enemyCounter);
enemyCounter++;
animComposer.setCurrentAction("walking");
}
//Creates the enemies model
private void createModel() {
model = assetManager.loadModel("/assets/Models/lowpoly_enemy.j3o");
model.scale(0.3f);
model.setLocalTranslation(getLocalTranslation());
attachChild(model);
ray = new Ray();
animComposer = getAnimComposer((Node) model);
setCullHint(CullHint.Never);
}
//Enemy attack method
public void attack() {
//If cooldown of 500 milliseconds attack player and print health
if (System.currentTimeMillis() - lastAttack > 500) {
lastAttack = System.currentTimeMillis();
isYellow = true;
player.health--;
System.out.println(getName());
animComposer.setCurrentAction("attacking");
action = "attack";
}
}
//After 200 milliseconds return the yellow head to red
public void endYellow() {
if (System.currentTimeMillis() - lastAttack > 200) {
isYellow = false;
//((Geometry)model.getChild("Sphere")).getMaterial().setColor("Color", ColorRGBA.Red);
}
}
public void endCyan() {
if (System.currentTimeMillis() - lastHit > 200) {
isCyan = false;
//((Geometry)model.getChild("Sphere")).getMaterial().setColor("Color", ColorRGBA.Red);
}
}
//Runs when the enemy is attacked
public void makeCyan() {
lastHit = System.currentTimeMillis();
isCyan = true;
//((Geometry)model.getChild("Sphere")).getMaterial().setColor("Color", ColorRGBA.Cyan);
}
private void update(float tpf) {
if (health <= 0) {
enemies.remove(this);
removeFromParent();
}
if(getName().equals("enemy6")) {
enemies.remove(this);
removeFromParent();
}
Vector3f enemyLocation = model.getWorldTranslation();
Vector3f playerDirection = cam.getLocation().subtract(enemyLocation);
Vector3f random = new Vector3f(new Vector3f(getRandomNumber(-3, 3), 0, getRandomNumber(-3, 3)));
//If the enemy is close then attack the player
float distance = enemyLocation.distance(cameraNode.getLocalTranslation());
if (distance < 5) {
attack();
} else {
if(action == "attack"){
animComposer.setCurrentAction("walking");
action = "walk";
}
}
Vector3f relative = cam.getLocation().subtract(model.getWorldTranslation());
relative.y = 0;
relative.normalizeLocal();
Quaternion rotation = new Quaternion().lookAt(relative, Vector3f.UNIT_Y);
model.setLocalRotation(rotation);
if(moveCheck(playerDirection, model.getWorldTranslation())) {
if (distance < 20) {
move(playerDirection.mult(.25f).mult(tpf));
}
} else if(moveCheck(random, enemyLocation)) {
move(random.mult(.25f).mult(tpf));
}
if(distance >= 20)if(moveCheck(random, enemyLocation))move(random);
if(distance <= 40){
idleTimer++;
if(idleTimer >= 500){
skeleton_idle.setLocalTranslation(getLocalTranslation());
skeleton_idle.playInstance();
idleTimer = 0;
}
}
//If e is yellow or cyan run make red
/* if (isYellow) {
endYellow();
}
else if (isCyan) {
endCyan();
}*/
}
}
now, I had an issue, my .j3o model came from a .gltf and it wasn’t lighting up. pspeed told me to add a lightprobe. I did and it worked fine but some of the enemies that were spawned were still black.