Can't use lookat() multiple times

i have an array created by method, when i debug everything looks fine but 1 out of 10 mob face where i want.

    private Node mob[] = new Node[number];
    private Node[] regularMob(Vector3f vec){
            for(int i = 0; i < number; i++){
                mob[i] = (Node) assetManager.loadModel("Models/Mob.j3o");
                control = mob[i].getControl(AnimControl.class);
                channel = control.createChannel();
            return mob;
        public void mobZ(int number){
            for(int i = 0; i < number;i++){
                Vector3f vec = new Vector3f(FastMath.nextRandomInt(-100, 100),0, FastMath.nextRandomInt(-100, 100));
    public void update(float tpf){
       for (int i = 0; i < number; i++){
            mob[i].lookAt(cam.getLocation(), Vector3f.UNIT_Y);
            mob[i].rotate(0, FastMath.DEG_TO_RAD * 180, 0);

Have you really looked at your code?:

Shouldn’t this method be like this?:

    private Node regularMob(Vector3f vec) {
        Node newMob = (Node) assetManager.loadModel("Models/Mob.j3o");


        control = newMob.getControl(AnimControl.class);
        channel = control.createChannel();

        return newMob;

And so on, adding the mob to the array after this method?:

    public void mobZ(int number) {
        Vector3f vec = new Vector3f(FastMath.nextRandomInt(-100, 100),0, FastMath.nextRandomInt(-100, 100));
        for(int i = 0; i < number; i++) {
            Node newMob = regularMob(vec);
            mob[i] = newMob;

In your original code you are overriding every array item each time on each iteration. So after the last mob is created, the full array is containing that mob.

1 Like

This is what the other reply is talking about. Each pass through the loop you create the entire array again and add the i’th item.

You ultimately end up with number * number amount of mobs and only the last ‘number’ of them will face the way you want.

Well, my very first game so. Thank you