class_name CameraController extends Node3D # have a base node which the child Camera3D will follow @export var movement_speed: float = 1.0 @onready var camera_3d: Camera3D = $Camera3D func _ready() -> void: #set the child Camera3D position and rotation. This part is absolutely optional and can be set in the inspector aswell camera_3d.position.x = 0.0 camera_3d.position.y = 1.0 camera_3d.position.z = 1.4 camera_3d.rotation_degrees.x = -35.0 camera_3d.rotation_degrees.y = 0.0 camera_3d.rotation_degrees.z = 0.0 camera_3d.fov = 30.0 func _physics_process(delta: float) -> void: var inputDirection : Vector3 = Vector3.ZERO if Input.is_action_pressed("cam_forward"): inputDirection -= transform.basis.z if Input.is_action_pressed("cam_back"): inputDirection += transform.basis.z if Input.is_action_pressed("cam_left"): inputDirection -= transform.basis.x if Input.is_action_pressed("cam_right"): inputDirection += transform.basis.x inputDirection = inputDirection.normalized() if Input.is_action_just_pressed("cam_rotate_left"): rotation_degrees.y -= 30 elif Input.is_action_just_pressed("cam_rotate_right"): rotation_degrees.y += 30 global_translate(inputDirection * delta * movement_speed)
or share this direct link: