NPC wont stop moving

So i got an NPC to randomly move in my game, however he keeps moving all the time and i want to him to stop so its more realisitc.
[java]
public void update() {
walkDirection.set(0, 0, 0);

    Random walk = new Random();
    if (walk.nextInt(1000) == 1) {
        walkDirection.set(walk.nextInt(5),0,walk.nextInt(5));
        ogre.setWalkDirection(walkDirection.normalize().multLocal(movementSpeed));
    }
    else if (walk.nextInt(1000) == 2) {
        walkDirection.set(walk.nextInt(5)-5,0,walk.nextInt(5)-5);
        ogre.setWalkDirection(walkDirection.normalize().multLocal(movementSpeed));
    }
}  [java]

He moves wherever the hell he wants and doesnt stop lol

well in one you use this and in the other ogre as the method call context, are those actually the same?

@Empire Phoenix said: well in one you use this and in the other ogre as the method call context, are those actually the same?

Yes its all in my Ogre class. Ogre is a CharacterControl variable.
[java]
private Vector3f walkDirection = new Vector3f();
private CharacterControl ogre;
[/java]

You only set the walkdirectin if its 1 or 2, but not else, so it is never set back to 0,0,0

@Empire Phoenix said: You only set the walkdirectin if its 1 or 2, but not else, so it is never set back to 0,0,0

I tried, it doesnt work.

Add systems out so you see where the code flows,

I can guarantee you that setting a walkdirection to 0,0,0 stops the movement.

1 Like
@Empire Phoenix said: Add systems out so you see where the code flows,

I can guarantee you that setting a walkdirection to 0,0,0 stops the movement.


Got it, thanks for your help!

1 Like