You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
765 B
GDScript
24 lines
765 B
GDScript
extends Camera3D
|
|
|
|
@export var ray_length := 1000.0
|
|
@export var target_path : NodePath
|
|
@export var height := 3.5
|
|
@onready var target_node : MeshInstance3D = get_node(target_path)
|
|
var projected_point := Vector3.ZERO
|
|
|
|
func _input(event):
|
|
if event is InputEventMouseMotion:
|
|
var from = project_ray_origin(event.position)
|
|
var to = from + project_ray_normal(event.position) * ray_length
|
|
var result = get_world_3d().direct_space_state.intersect_ray(
|
|
PhysicsRayQueryParameters3D.create(from, to)
|
|
)
|
|
if result and result.get('position'):
|
|
projected_point = result.get('position')
|
|
|
|
func _physics_process(_delta):
|
|
if projected_point:
|
|
target_node.global_position = (
|
|
projected_point + projected_point.direction_to(global_position).normalized() * height
|
|
)
|