Godot movement 2d problem spaceship

Godot Version

Godot 4.3

Question

When I turn to 12 o’clock and press in front, I fly in front. But when I turn 3 o’clock and press in front, I’m not flying for 3 hours, but for 1.5 hours. I want it to turn from 12 o’clock to 3 o’clock.

extends CharacterBody2D

@export var speed = 400
@export var rotation_speed: float = 0.8
var max_speed = 500
var rotation_direction: float = 0.0
var forward_input = 0
var forward_direction = Vector2.UP

func get_input():
	rotation_direction = Input.get_axis("ui_left", "ui_right")
	forward_input = Input.get_axis("ui_down", "ui_up")

func _process(delta):
	get_input()
	if rotation_direction != 0:
		rotation += rotation_direction * rotation_speed * delta
		forward_direction = Vector2.UP.rotated(rotation)
	if forward_input != 0:
		velocity += forward_direction * forward_input * speed * delta
	
	print(position)
	print(velocity)
	print(rotation)
	move_and_slide()

Is there any chance your sprite is additionally being rotated at the same rate as your CharacterBody2D?

Is anything attenuating your velocity? It looks to me like you’re just accumulating velocity, so if you start at 12:00 and turn to 3:00, you’ll have accumulated a lot of velocity towards 12:00, then 1:00, then 2:00… the cumulative velocity will have you moving somewhere between your initial facing and your final facing.

Something needs to do velocity *= 0.8 every update or something so you bleed off the old vectors, or you need to clamp max velocity after adding in the new.

1 Like