35 lines
956 B
GDScript
35 lines
956 B
GDScript
extends XROrigin3D
|
|
|
|
@export var keyboard_enabled := true
|
|
@export var keyboard_speed := 3.0
|
|
@export var keyboard_turn_speed := 90.0 # Grad pro Sekunde
|
|
|
|
func _process(delta):
|
|
if not keyboard_enabled:
|
|
return
|
|
|
|
var camera = $XRCamera3D
|
|
if not camera:
|
|
return
|
|
|
|
var direction = Vector3.ZERO
|
|
|
|
if Input.is_key_pressed(KEY_W):
|
|
direction -= camera.global_transform.basis.z
|
|
if Input.is_key_pressed(KEY_S):
|
|
direction += camera.global_transform.basis.z
|
|
if Input.is_key_pressed(KEY_A):
|
|
direction -= camera.global_transform.basis.x
|
|
if Input.is_key_pressed(KEY_D):
|
|
direction += camera.global_transform.basis.x
|
|
|
|
if direction != Vector3.ZERO:
|
|
direction.y = 0 # Keine vertikale Bewegung
|
|
direction = direction.normalized()
|
|
global_position += direction * keyboard_speed * delta
|
|
|
|
if Input.is_key_pressed(KEY_Q):
|
|
rotate_y(deg_to_rad(keyboard_turn_speed * delta))
|
|
if Input.is_key_pressed(KEY_E):
|
|
rotate_y(deg_to_rad(-keyboard_turn_speed * delta))
|