Godot Version 4.3
I want to create a spaceship so that it accelerate and decelerates using ui_up, ui_down. Also, so that it turns into ui_right, ui_left. It is necessary for the ship to move in the direction of the ship. I don’t understand how to take a direction and have the ship move in that direction.
extends CharacterBody2D
var engine_thrust = 100
var accelerate = Vector2()
var rotation_dir = 0
func get_input():
if Input.is_action_pressed("ui_up"):
accelerate += Vector2(engine_thrust, 0)
if Input.is_action_pressed("ui_down"):
accelerate -= Vector2(engine_thrust, 0)
rotation_dir = 0
if Input.is_action_pressed("ui_right"):
rotation_dir += 0.1
if Input.is_action_pressed("ui_left"):
rotation_dir -= 0.1
print(rotation_dir)
func _process(delta):
get_input()
rotation += rotation_dir
velocity = accelerate
move_and_slide()