immersive-home/app/addons/godot-xr-tools/objects/grab_points/grab_point.gd

29 lines
819 B
GDScript3
Raw Normal View History

2023-10-16 20:10:20 +03:00
class_name XRToolsGrabPoint
extends Marker3D
## XR Tools Grab Point Base Script
##
## This script is the base for all grab points. Pickable object extending from
## [XRToolsPickable] can have numerous grab points to control where the object
## is grabbed from.
## If true, the grab point is enabled for grabbing
@export var enabled : bool = true
2023-12-14 01:03:03 +02:00
## Evaluate fitness of the proposed grab, with 0.0 for not allowed.
func can_grab(grabber : Node3D, _current : XRToolsGrabPoint) -> float:
if not enabled:
return 0.0
# Return the distance-weighted fitness
return _weight(grabber)
# Return a distance-weighted fitness weight in the range (0.0 - max]
func _weight(grabber : Node3D, max : float = 1.0) -> float:
var distance := global_position.distance_to(grabber.global_position)
return max / (1.0 + distance)