2023-01-08 08:22:44 +00:00
|
|
|
extends Node
|
|
|
|
|
2023-01-08 09:11:38 +00:00
|
|
|
@export var force_multiplier: float
|
|
|
|
@export var target: RigidBody3D
|
2023-01-08 08:22:44 +00:00
|
|
|
|
|
|
|
# Must be BELOW the player node to work!
|
|
|
|
@onready var magnet_area: Area3D = $MagnetArea
|
|
|
|
@onready var player: CharacterBody3D = get_tree().root.find_child("Player", true, false)
|
|
|
|
|
|
|
|
|
|
|
|
var captured = false
|
|
|
|
|
|
|
|
|
|
|
|
func capture():
|
|
|
|
captured = true
|
|
|
|
|
|
|
|
|
|
|
|
func _physics_process(delta):
|
|
|
|
if captured:
|
2023-01-08 09:11:38 +00:00
|
|
|
var direction = player.position - target.position
|
2023-01-08 08:22:44 +00:00
|
|
|
var force = direction.normalized() * force_multiplier * delta
|
2023-01-08 09:11:38 +00:00
|
|
|
target.apply_force(force)
|
2023-01-08 08:22:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _on_magnet_area_body_entered(body: Node3D):
|
|
|
|
if body.name == "Player":
|
|
|
|
print("Player captured pickup!")
|
|
|
|
capture()
|