cawez_puzzlebox/primitives/assign_force/assign_force.gd
2024-06-29 21:57:20 -04:00

26 lines
658 B
GDScript

extends Area3D
@export var velocity = Vector3.ZERO
var body_within
@export var tolerance = 200.0
# Called when the node enters the scene tree for the first time.
func _ready():
body_entered.connect(_on_area_entered)
body_exited.connect(_on_area_exit)
func _process(delta):
if body_within != null:
if (get_parent_node_3d().quaternion * velocity).dot(body_within.linear_velocity) > tolerance :
body_within.linear_velocity = get_parent_node_3d().quaternion * velocity
func _on_area_entered(body : RigidBody3D) -> void:
print("Entered!")
body_within = body
func _on_area_exit(body : RigidBody3D) -> void:
print("Exit!")
body_within = null