Godot Version
Godot 3.6.1
Question
In my game you can steer a rocket left and right. When you flip to the left, all is fine. But when you flip to the right, after about 1.5 full rotations the rocket bugs out. It becomes kind of stuck and steering doesn’t work anymore.
Video for clarification: Screen Recording 2025-09-12 at 23.04.45
This bug has been haunting me for over a year now. I’ve tried to fix it on multiple occasions and now I just don’t know what to do anymore.
If anyone knows what the problem might be, please let me know.
The rocket is a RigidBody2D. It has a child RigidBody2D “Engine” on which the steering impulse is applied. See image and code.
Code
func _physics_process(delta: float) -> void:
_apply_thrust()
_apply_steering()
func _get_rocket_direction() → float:
# Save the rocket’s up facing direction in radians
# PI / 2 = 90 degrees
var rocket_direction: float = wrapf(rotation - PI / 2, -PI, PI)
return rocket_direction
func _apply_thrust() -> void:
# Apply thrust
# Happens continuously
if Input.is_action_pressed("ui_rocket_thruster"):
# Get the rocket's up facing direction in radians
var rocket_direction = _get_rocket_direction()
# Convert radians to vector2
var thrust_direction: Vector2 = Vector2(cos(rocket_direction), sin(rocket_direction))
# Apply thrust
engine.apply_central_impulse(thrust_direction * thrust_power)
# Increase fuel usage
fuel_used += fuel_usage
func _apply_thrust() → void:
# Apply thrust
# Happens continuously
if Input.is_action_pressed(“ui_rocket_thruster”):
# Get the rocket’s up facing direction in radians
var rocket_direction = _get_rocket_direction()
# Convert radians to vector2
var thrust_direction: Vector2 = Vector2(cos(rocket_direction), sin(rocket_direction))
# Apply thrust
engine.apply_central_impulse(thrust_direction * thrust_power)
# Increase fuel usage
fuel_used += fuel_usage
func _apply_steering() -> void:
# Get the rocket's up facing direction in radians
var rocket_direction = _get_rocket_direction()
# Get the steering direction, either +1 (left), 0 or -1 (right)
var steering: float = Input.get_action_strength("ui_left") - Input.get_action_strength("ui_right")
if steering:
is_steering = true
var steering_direction_vector: Vector2 = Vector2.RIGHT.rotated(rocket_direction + steering * (PI / 2))
# Apply steering
engine.apply_central_impulse(steering_direction_vector * steering_power * steering_power_multiplier)
else:
is_steering = false