Currently, I am working on developing a 2D game and facing a challenge in making the bullets move towards the cursor. Here is the code snippet that I have been using:
let xDist = this.game.input.mousePointer.x - this.x;
let yDist = this.game.input.mousePointer.y - this.y;
let angle = Math.atan(yDist / xDist);
this.projectile_sprite.setVelocityX(yDist);
this.projectile_sprite.setVelocityY(xDist);
I have noticed that the projectile moves faster when it is further away from the cursor, which is not the intended behavior. Can you suggest a solution to fix this issue?