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:
- https://labs.phaser.io/edit.html?src=src%5Cphysics%5Carcade%5Cvelocity%20from%20angle.js
- https://phaser.discourse.group/t/detect-the-cardinal-direction-of-mouse-pointer/3795
- https://phaser.io/examples/v3/view/pools/bullets
My apologies for flooding the discussion board…