godot-steering-ai-framework/project/demos/Arrive3d/Camera.gd
Francois Belair ca1839c633 Add 3D demo and fix 3D agents
Closes #30, closes #31, closes #33
2020-02-13 03:51:48 -05:00

26 lines
568 B
GDScript

extends Camera
var target: Spatial
onready var ray := $RayCast
func _unhandled_input(event: InputEvent) -> void:
if event is InputEventMouseMotion:
_set_target_position(event.position)
func setup(_target: Spatial) -> void:
self.target = _target
_set_target_position(get_viewport().get_mouse_position())
func _set_target_position(position: Vector2) -> void:
var to = project_local_ray_normal(position) * 10000
ray.cast_to = to
ray.force_raycast_update()
if ray.is_colliding():
var point = ray.get_collision_point()
target.transform.origin = point