46 lines
1.3 KiB
GDScript
46 lines
1.3 KiB
GDScript
extends Camera3D
|
|
|
|
var cameraPivot: Node3D
|
|
|
|
func _ready() -> void:
|
|
cameraPivot = get_parent()
|
|
|
|
if not cameraPivot.visible:
|
|
cameraPivot.queue_free()
|
|
|
|
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
|
|
|
func _process(delta: float) -> void:
|
|
if not cameraPivot.visible:
|
|
return
|
|
|
|
if Input.is_action_just_pressed("pause"):
|
|
if Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
|
|
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
|
else:
|
|
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
|
|
|
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
func _physics_process(delta: float) -> void:
|
|
if not cameraPivot.visible:
|
|
return
|
|
|
|
var input_dir = Input.get_vector("player_left", "player_right", "player_forwards", "player_backwards")
|
|
var direction = (cameraPivot.transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
|
|
|
|
if Input.is_action_pressed("player_crouch"):
|
|
cameraPivot.position.y -= 30 * delta
|
|
if Input.is_action_pressed("player_blink"):
|
|
cameraPivot.position.y += 30 * delta
|
|
|
|
cameraPivot.position.x += (direction.x * 30) * delta
|
|
cameraPivot.position.z += (direction.z * 30) * delta
|
|
|
|
|
|
func _input(event: InputEvent) -> void:
|
|
if not cameraPivot.visible:
|
|
return
|
|
|
|
if event is InputEventMouseMotion and Input.mouse_mode == Input.MOUSE_MODE_CAPTURED:
|
|
rotation.x -= event.relative.y / 360
|
|
cameraPivot.rotation.y -= event.relative.x / 360
|