Patrol route issue

I know this has probably been covered before, but I am having a basic level problem. First, I have the Jaime monkey navigation to a point, and while I can get the monkey to travel to the point via AI, once there I cannot get him to move again. I want to establish a basic patrol route, ie he begins at:
aiCharacter.setLocalTranslation(0, 10, 0);
then navigates to
navMesh.moveTo(new Vector3f (85, 10, -85));
Once there, a condition is tripped and he moves back to:
navMesh.moveTo(new Vector3f (0, 10, 0));

any if; if else statement I try does not work. My code for the aiCharacter is below:

private void setupCharacter(Node scene) {
    //This creates my AI character
    Node aiCharacter = (Node) assetManager.loadModel("Models/Jaime/Jaime.j3o");
    AICharacterControl physicsCharacter = new AICharacterControl(0.3f, 2.5f, 8f);
    aiCharacter.addControl(physicsCharacter);
    bulletAppState.getPhysicsSpace().add(physicsCharacter);
    aiCharacter.setLocalTranslation(0, 10, 0);
    aiCharacter.setLocalScale(2f);
    scene.attachChild(aiCharacter);        
    NavMeshNavigationControl navMesh = new NavMeshNavigationControl((Node)scene);
    aiCharacter.addControl(navMesh);
    //MotionPath path = new MotionPath();  
    
     if (aiCharacter.getLocalTranslation().getZ() == -85) {
         
         navMesh.moveTo(new Vector3f (0, 10, 0));
     }
     
     if (aiCharacter.getLocalTranslation().getZ() == 0) {
         navMesh.moveTo(new Vector3f (85, 10, -85));
     }
 
}

I call this in public void simpleInitApp()

To answer your question as you ask it:
You’ve got a “hidden bug” that I can see, only because of what you are “not showing”. Float values in a 3d engine rarely equal a value “exactly” due to floating point precision. Rather, try to aim for “close enough” with your logic.

so go for:

if ((aiCharacter.getLocalTranslation().getZ()  < (0f + 0.1f)) &&
(aiCharacter.getLocalTranslation().getZ()  > (0f - 0.1f)) ) {
    navMesh.moveTo(new Vector3f (85, 10, -85));
}

edit: you can ignore the rest of this :sweat_smile:
and as a bonus:

try adding in some support architecture to make it easier on you.

  • Set Up a “OrderedList” type situation (you can always loop it, or if you just want to fire off one shot events go with a “Queue”)
  • make sure to add a boolean “isTaskDone” type trigger.
  • if the “Task” is done, load up the next “Task” and unset the “isTaskDone” trigger.

Game On,
Charles