41 lines
1.1 KiB
GDScript
41 lines
1.1 KiB
GDScript
extends Camera3D
|
|
|
|
var rayRange = 2000
|
|
|
|
@onready var crosshair = %CrosshairCenter
|
|
@export var terminal: TerminalControls
|
|
|
|
|
|
func _physics_process(delta: float) -> void:
|
|
Get_Camera_Collision()
|
|
|
|
|
|
func Get_Camera_Collision():
|
|
var centre = get_viewport().get_size()/2
|
|
|
|
var rayOrigin = project_ray_origin(centre)
|
|
var rayEnd = rayOrigin + project_ray_normal(centre)*rayRange
|
|
|
|
var newIntersection = PhysicsRayQueryParameters3D.create(rayOrigin, rayEnd)
|
|
var intersection = get_world_3d().direct_space_state.intersect_ray(newIntersection)
|
|
|
|
var is_highlighted = not intersection.is_empty()
|
|
|
|
if crosshair and is_instance_valid(crosshair):
|
|
crosshair.set_highlight(is_highlighted)
|
|
|
|
func _input(event: InputEvent) -> void:
|
|
if event is InputEventKey and event.pressed and crosshair.is_highlighted:
|
|
if event.is_echo(): return
|
|
|
|
if event.keycode == KEY_BACKSPACE:
|
|
terminal.InputDelChar()
|
|
|
|
if event.unicode > 31:
|
|
var character = char(event.unicode)
|
|
if terminal: # Check that you assigned the node in the Inspector
|
|
terminal.InputChar(character)
|
|
|
|
if event.keycode == KEY_ENTER:
|
|
terminal.EnterCommand()
|