Create a new scene with Area2D as root node
VisibleOnScreenNotifier2D
Save scene as bullet.tscn
Add a New Capsule2D shape for the CollisionShape
Add a script to the Bullet node
Add an export var for bullet speed
_transform holds position & rotation for bullet
move bullet in x direction
Continuously update the position of the bullet on screen in the process function
VisibleOnScreenNotifier2D tells us via a signal if a node is visible on the screen or not. We will use this signal to delete bullets which have gone off-screen.
Code the screen exited function
To delete off-screen bullets
Code the body entered function
Connect both signals in code or inspector
We need to know where the lasers will appear from in relation to the ship. Remember that the ship could be facing in any direction and at any rotation.
Return to the Player scene
Add new variables to the player script
Add the bullet scene in the Inspector
Set the timer's wait time
Create the shoot function
You can't shoot while invulnerable or dead or in cooldown
Otherwise toggle can_shoot
call the bullet start function
In the get input function
Toggle the cooldown timer
By connecting the timeout signal
Either in code or the Inspector