Need help recreating Asteroid Controls

Godot Version v4.2

New to Godot and coding in general, followed some forums and was able to make my character rotate but not move forward. Attempting to recreate on asteroids controls. Code runs, just not able to move forward.

extends CharacterBody2D

@export var speed = 100
@export var rotation_speed = 3.5

var rotation_direction = 0
var motion = 0

func get_input():
print(motion)

rotation_direction = Input.get_axis("left", "right")

if Input.is_action_pressed("forward"):
	motion = transform.x * speed
elif Input.is_action_just_released("forward"):
	motion = lerp(transform.x, Vector2(rotation_direction,0), 0.5)

func _physics_process(delta):
rotation += rotation_direction * rotation_speed * delta
get_input()
move_and_slide()

Change your motion to velocity in the code and delete the motion variable declaration at the top.

var motion = 0

And please use preformatted text to format your code with ``` in the future.

1 Like