target_from_mousepos.gd 386 B

1234567891011121314151617181920
  1. extends Camera3D
  2. @export var MOVEMENT_SPEED: float = 12
  3. @export var flip_axis: bool = false
  4. @onready var targets = $Targets
  5. func _process(_delta):
  6. var mouse_to_world = (
  7. project_local_ray_normal(get_viewport().get_mouse_position()) * MOVEMENT_SPEED
  8. )
  9. if flip_axis:
  10. mouse_to_world = -mouse_to_world
  11. else:
  12. mouse_to_world.z *= -1
  13. targets.transform.origin = mouse_to_world