How can I get my projectiles to shoot in the direction the player is facing in an asteroid-type game?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By MercyFalls

I just got the player movement to work like left and right rotate and up moves you in the direction you’re facing so I just need to figure out how to get the lasers to fire in the same direction that you’re currently facing. I tried to use position2d node but couldn’t get it to work in the shoot functions because I have it located in a separate scene from the player.

:bust_in_silhouette: Reply From: CollyBlargle

There is a good example in the Godot documentation. The key is sending the angle of your player to the bullet when it first spawns.

https://github.com/LuckyCanary/AsteroidGame/tree/main

So, I tried to follow the Godot documentation you suggested and I managed to have the laser spawn at the end of my ship in whatever direction it’s facing but now the lasers shoot to the right of my ship instead of from the front of it. Any ideas? I’ve posted the code to my player and laser.

Here is a screenshot of the laser shooting sideways as you can see, it spawns out of the Muzzle like I want it too though

https://github.com/LuckyCanary/AsteroidGame/blob/main/AsteroidGame.png

https://github.com/LuckyCanary/AsteroidGame/blob/main/asteroidgame2.png

As you can see it changes directions based on the player’s rotation but it just shoots to the right of the ship instead of to the top

EDIT: Also, for some reason now when I get a game over and restart the game, the game will crash when I try to shoot my laser and give me an error of null instance

MercyFalls | 2021-08-02 20:23