Change lines 15 through 19 to the following:
if Input.is_action_pressed("ui_up"):
var forward_direction = Vector2(cos(rotation), sin(rotation))
velocity -= forward_direction * speed * delta
if Input.is_action_pressed("ui_down"):
var forward_direction = Vector2(cos(rotation), sin(rotation))
velocity += forward_direction * speed * delta
I have not tested the code, but I think it should work.
What this does is that it takes the rotation and converts it into a position around the unit circle. This GIF shows an example of what is happening:
https://media.giphy.com/media/fzRG2T0jDujcI/giphy.gif
In the GIF above, rotation is the angle and the point on the green circle is what we are storing in the forward_direction variable.
By multiplying by speed and delta, we are basically changing the magnitude/length of the unit circle position. We can then add/subtract this position to velocity, and that will should move it in the correct direction. :smile:
I probably explained how it works poorly. My brain is working on autopilot right now :sweat_smile:
Hopefully the code above helps a bit!
(Side note: Welcome to the forums)