I’m creating this wave-based shooter, and every enemy will follow the player directly (ignoring walls), and I want to attach each enemy to a node, to the enemyNode, and doing this works, but the fact that I want all the enemies to move with a control got difficult. This is my current control’s update state, which is connected to the Spatial of an enemy.
CharacterControl car = spatial.getControl(CharacterControl.class);
walkDirection1.set(0,0,0);
npcLocation = car.getPhysicsLocation();
System.out.println(playerLocation);
float x = playerLocation.x - npcLocation.x;
float z = playerLocation.z - npcLocation.z;
float maxMove = FastMath.abs(x) + FastMath.abs(z);
float heightDif = playerLocation.y - npcLocation.y;
if(heightDif > 3 && jumpCooldown < 0 && spatial.getControl(CharacterControl.class).onGround()) {
spatial.getControl(CharacterControl.class).jump(new Vector3f(0,20f,0));
jumpCooldown = 1;
}
spatial.lookAt(new Vector3f(playerLocation.x,npcLocation.y,playerLocation.z), new Vector3f(0,1,0));
spatial.getControl(CharacterControl.class).setWalkDirection(walkDirection1.multLocal(0.4f));
jumpCooldown = jumpCooldown - 1 * tpf;
spatial.getControl(CharacterControl.class);
Reading the docs and other posts, I found that using the code…
spatial.getControl(CharacterControl.class)
…should give me access to the spatial’s control, mainly because controls cannot have controls. Wit this sample for the control, spatial.getControl(CharacterControl.class).method() isn’t working, but using it for not a method (example, getting a value from a control) does work.
I feel like I’m missing something out, like not returning something. Can anyone point me in the right direction and explain what I should do?