31 lines
801 B
GDScript
31 lines
801 B
GDScript
extends RigidBody3D
|
|
|
|
var torque_force: float = 10000.0
|
|
|
|
func _physics_process(delta):
|
|
var local_torque := Vector3.ZERO
|
|
|
|
# Pitch
|
|
if Input.is_action_pressed("w"):
|
|
local_torque.x -= 1
|
|
if Input.is_action_pressed("s"):
|
|
local_torque.x += 1
|
|
|
|
# Yaw
|
|
if Input.is_action_pressed("a"):
|
|
local_torque.y -= 1
|
|
if Input.is_action_pressed("d"):
|
|
local_torque.y += 1
|
|
|
|
# Roll
|
|
if Input.is_action_pressed("q"):
|
|
local_torque.z += 1
|
|
if Input.is_action_pressed("e"):
|
|
local_torque.z -= 1
|
|
|
|
# Apply local torque converted to world space
|
|
if local_torque != Vector3.ZERO:
|
|
var world_torque = global_transform.basis * local_torque.normalized() * torque_force * delta
|
|
apply_torque(world_torque)
|
|
|
|
print(angular_velocity) |