Trouble making AI follow player

Hi all,

I´m currently playing around with some basic AI. At the moment I´m just trying to make a box follow the player/cam, as well as navigate by using a NavMesh.

My problem is the movement of the box is not consistent. It´s trying to follow the player around, but most of the time it is just “shaking” in the same location.
If I move the cam the box sometimes continues to follow the cam for a short period of time. I´m probably doing the translations wrong somewhere, but I´m not sure.

The relevant code looks like this:

private CharacterControl follower;

Box box = new Box(1,1,1);
geometry = new Geometry (“My target”, box);
Material unshadedMat = new Material (assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

BoxCollisionShape boxShape = (BoxCollisionShape) CollisionShapeFactory.createBoxShape(geometry);
follower = new CharacterControl(boxShape, 0.05f);
follower.setPhysicsLocation(new Vector3f(0, 20, 0));


//AI Navigation
Mesh mesh = ((Geometry) gameLevel.getChild(“NavMesh”)).getMesh();
NavMesh navMesh = new NavMesh(mesh);

navi = new NavMeshPathfinder(navMesh);

//compute new path (probably should do that on another thread, note the class is not “thread safe” per se)

Then in the simpleUpdate method:

//AI stuff
//getNextWayPoint will return always the same waypoint until we manually advance to the next

Waypoint wayPoint = navi.getNextWaypoint();
if(wayPoint == null) {
Vector3f vector = wayPoint.getPosition().subtract(follower.getPhysicsLocation());
if (!(vector.length() < 1)) {
    //move the spatial to location while its not there
    follower.setWalkDirection(vector.normalize().multLocal(tpf * 20));
    //geometry.move(vector.normalize().multLocal(tpf * 20));
else {
    //if we are at the waypoint already, go to the next one


Any clues on what´s wrong here?

Why are you manually copying the location of the character over instead of just attaching it to the geometry :?

How can I do that? I can´t find any attach function for the geometry.


Guess that´s what I`m doing on line 14 in the first code window?
So I can just remove the line
geometry.setLocalTranslation(follower.getPhysicsLocation()) ?

Right, yeah.