target_from_mousepos.gd 379 B

1234567891011121314151617
  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 = project_local_ray_normal(get_viewport().get_mouse_position()) * MOVEMENT_SPEED
  7. if flip_axis:
  8. mouse_to_world = -mouse_to_world
  9. else:
  10. mouse_to_world.z *= -1
  11. targets.transform.origin = mouse_to_world