How to detect directions when shooting

Hello I am making my first game in phaser but I get stuck in the shots, I have three problems the first is that I want the projectiles to come out depending on where my player looks, second when he looks to the left the projectile has to come out in the corresponding direction (x, y) and not in the distance like when I look to the right, third that I only want to fire 5 shells from time to time and not all at once.

I was looking for some game in github like the contra or metal slug in phaser 3 to read the code but I did not find anything about it, the only example I found where what I want is applied is in this game but it is done in a very old version way by phaser. Bullets with Phaser – Kumansenu Does Things

Here is my code with the problem I am a newbie: https://codepen.io/DevGame/pen/MWvOzRK

Hey there,

fixed the following problems for you in this fork of your codepen:

1. I want the projectiles to come out depending on where my player looks
=> Whenever the direction is changed via WASD, I set a player variable this.player.direction

2. when he looks to the left the projectile has to come out in the corresponding direction
=> just checking the new variable this.player.direction in the shootBullet method

Hope this helps :slight_smile: Unfortunately I can’t help with the 3rd problem.

2 Likes

Ok, you can’t leave me everything on a silver platter XD a thousand thanks