Pointer move function

Hi, I have a code that allows my turret to move wherever the cursor is moved to, however, it only moves 45 degrees instead of moving freely.

Here is my code:

this.input.on(‘pointermove’, function (pointer) {

        turret.rotation = Phaser.Math.Angle.Between(turret.x, turret.y, pointer.x, pointer.y);
        
    }, this);
1 Like

Cool! I never knew about this tidbit of code, I always used basic trig to figure out the angle.

For me, the code works perfectly. Perhaps you need to adjust the origin of your object? For instance, if your object is nested inside of a container and the container is located at (0, 0), then your turret will only point between 270 degrees and 360.

Thank you, I came to the realisation my image/website was bugged for some apparent reason, it works totally fine now