Point and shoot problem

Hello again,
So I am creating an Isometric style game with phaser 3.
I can’t explain what problem I’ve been facing so I recorded it:

Codes that scope the problem:

velocityFromRotation = this.physics.velocityFromRotation;
velocity = new Phaser.Math.Vector2();
var Bullet = new Phaser.Class({

    Extends: Phaser.GameObjects.Sprite,

    initialize:

    function Bullet (scene)
    {
        Phaser.GameObjects.Sprite.call(this, scene, 0, 0, 'bullet');

        this.speed = Phaser.Math.GetSpeed(400, 0.5);
        scene.physics.world.enable(this);
    },

    fire: function (x, y)
    {
        this.setPosition(x, y - 50);
        this.setActive(true);
        this.setVisible(true);
    },

    update: function (time, delta)
    {
        this.body.setVelocity(velocity.x+100,velocity.y+100);
        if (this.y < -50)
        {
            this.setActive(false);
            this.setVisible(false);
        }
    }

});

bulletGroup = this.physics.add.group({
    classType: Bullet,
    maxSize: 50,

    runChildUpdate: true
});    

this.input.on('pointerdown', function (pointer) {
    var angle = Phaser.Math.Angle.Between(swat.x, swat.y, pointer.worldX, pointer.worldY);
    var angleSnap = Phaser.Math.Snap.To(angle, SNAP_INTERVAL);
    var angleSnapDeg = Phaser.Math.RadToDeg(angleSnap);
    direction = directions[angleSnapDeg];
    action="shooting";
    velocityFromRotation(angle, 600, velocity);
}, this);  

Several techniques that I’ve used:

My apologies for flooding the discussion board…

Remove this line:

this.body.setVelocity(velocity.x+100,velocity.y+100);

And you probably want to apply the angle when the bullet is fired, something like

function fire (x, y, angle)
{
    this.setPosition(x, y - 50);
    this.setActive(true);
    this.setVisible(true);
    this.scene.physics.velocityFromAngle(angle, this.speed, this.body.velocity);
}


What I did:

  • Increasing XY Velocity: this.body.setVelocity(200,200);

  • Used the velocity variable from: velocityFromRotation(angle, 600, velocity);

Current Code:

velocityFromRotation = this.physics.velocityFromRotation;
velocity = new Phaser.Math.Vector2();
var Bullet = new Phaser.Class({

    Extends: Phaser.GameObjects.Sprite,

    initialize:

    function Bullet (scene)
    {
        Phaser.GameObjects.Sprite.call(this, scene, 0, 0, 'bullet');

        this.speed = Phaser.Math.GetSpeed(400, 0.5);
        scene.physics.world.enable(this);
    },

    fire: function (x, y)
    {
        this.setPosition(x, y - 50);
        this.body.setVelocity(200,200);
        //console.log(this.body.velocity);
        this.setActive(true);
        this.setVisible(true);
        this.scene.physics.velocityFromAngle(angle, this.speed, this.body.velocity);
    },

    update: function (time, delta)
    {
        //this.body.setVelocity(velocity.x+100,velocity.y+100);
        if (this.y < -50)
        {
            this.setActive(false);
            this.setVisible(false);
        }
    }

});

bulletGroup = this.physics.add.group({
    classType: Bullet,
    maxSize: 50,

    runChildUpdate: true
});    

this.input.on('pointerdown', function (pointer) {
    angle = Phaser.Math.Angle.Between(swat.x, swat.y, pointer.worldX, pointer.worldY);
    
    var angleSnap = Phaser.Math.Snap.To(angle, SNAP_INTERVAL);
    var angleSnapDeg = Phaser.Math.RadToDeg(angleSnap);
    direction = directions[angleSnapDeg];
    action="shooting";
    velocityFromRotation(angle, 600, velocity);
}, this);    

}

Thank you for your reply.