xrjamfeb2025/scenes/manipulator.gd

31 lines
1 KiB
GDScript

# a vector field manipulator that can be picked up and radius resized by the
# holding controller's joystick.
# needs a VisualAttractorSphere child node to work.
class_name Manipulator
extends XRToolsPickable
var held_controller: XRController3D = null
@onready var attractor: GPUParticlesAttractorSphere3D = $VisualAttractorSphere
const MIN_SCALE = 0.5
const MAX_SCALE = 10
const SCALE_SPEED = 1.0
func _ready() -> void:
super()
picked_up.connect(_on_pickable_object_picked_up)
dropped.connect(_on_pickable_object_dropped)
func _process(delta: float) -> void:
if held_controller:
var joystick_y = held_controller.get_vector2("primary").y
if abs(joystick_y) > 0.1:
var new_radius = attractor.radius + (joystick_y * SCALE_SPEED * delta)
attractor.radius = clamp(new_radius, MIN_SCALE, MAX_SCALE)
func _on_pickable_object_picked_up(pickable: XRToolsPickable) -> void:
held_controller = pickable.get_picked_up_by_controller()
func _on_pickable_object_dropped(_pickable: XRToolsPickable) -> void:
held_controller = null