Godot Version
v4.4.1 Stable
Question
As the title says when I use my keybind for turning I add torque and it maxes out at a rotation and when i let go it snaps back to the original. I want it to continue turning and stay at that turning angle. I searched online and found something about angular_damp but i changed this and it did nothing. Angular damp is at zero.
Controller.gd:
extends Node3D
@export var rigidbody: RigidBody3D
@export var throttle_acceleration: float = 0.5
@export var turn_speed: float = 0.6
@export var speed: float = 1.5
@onready var rudder = $"Rudder"
var throttle: float = 0.0
func round_place(num, places):
return round(num * pow(10, places)) / pow(10, places)
func process(delta: float) -> void:
# Handle throttle input
if Input.is_action_pressed("move_forward"):
throttle = clamp(throttle + throttle_acceleration * delta, -0.6, 1.0)
elif Input.is_action_pressed("move_backward"):
throttle = clamp(throttle - throttle_acceleration * delta, -0.6, 1.0)
else:
if abs(throttle) < 0.1:
throttle = 0.0
# Handle turning input
var turn_direction = 0.0
if Input.is_action_pressed("move_left"):
turn_direction += 1.0
if Input.is_action_pressed("move_right"):
turn_direction -= 1.0
# Apply forces to the rigidbody
var forward_force = transform.basis.z * throttle * speed
rigidbody.apply_force(forward_force, rudder.position)
if turn_direction != 0.0:
var turn_torque = turn_direction * turn_speed * 20
rigidbody.apply_torque(Vector3.UP * turn_torque)
print("Throttle: ", throttle, " Turn Direction: ", turn_direction)
Angular Settings:
Video: Imgur: The magic of the Internet