[SOLVED] CharacterControl, control?

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?

We would need a specific example of this not working since “method()” is not a method on CharacterControl. If you call methods on CharacterControl then it will work fine.

I was just using an example, in my code I used…

 spatial.getControl(CharacterControl.class).setWalkDirection(walkDirection1.multLocal(0.4f));

…but that didn’t work. Is it because I can’t access it, or is it because how I got my values was wrong?

I decided to examine the other lines of code, and aparently…

 if(heightDif > 3 && jumpCooldown < 0 && spatial.getControl(CharacterControl.class).onGround()) {
  spatial.getControl(CharacterControl.class).jump(new Vector3f(0,20f,0));
    jumpCooldown = 1;
}

…does indeed work (enemy jumps), which means…

 spatial.getControl(CharacterControl.class).setWalkDirection(walkDirection1.multLocal(0.4f));

…should work, unless the information I gave to it is incorrect. I’ll look into this, and reply if any errors show up.

EDIT: I was right, the info wasen’t given correctly, and I never added the info to the walkdirection1. Consider this solved.

might be im missing something super obvious though to me it looks like the code does what its supposed to do:
in case the height difference is greater than 3, the npc is ready to jump and on ground, it does jump, it also looks at the player (not up or down though) and sets its walkDirection to 0, multiplied locally by 0.4f which still is 0f.

in your second line you set walkDirection1 to 0 and dont set any other values before you multiply it with 0.4 and apply it to the charactercontrol, doesnt your IDE tell you that variable maxMove is not used?

EDIT: meh i was too late, glad you fixed it!