2023-01-08 08:22:44 +00:00
|
|
|
extends Node
|
|
|
|
|
2023-01-08 20:27:26 +00:00
|
|
|
|
2023-01-08 09:11:38 +00:00
|
|
|
@export var force_multiplier: float
|
2023-01-08 20:27:26 +00:00
|
|
|
@export_node_path(RigidBody3D) var target_path: NodePath
|
|
|
|
@export var is_magnetized := false
|
2023-01-08 08:22:44 +00:00
|
|
|
|
2023-01-08 20:27:26 +00:00
|
|
|
@onready var target: RigidBody3D = get_node(target_path)
|
2023-01-08 08:22:44 +00:00
|
|
|
|
2023-01-08 20:27:26 +00:00
|
|
|
signal magnetized()
|
2023-01-08 08:22:44 +00:00
|
|
|
|
|
|
|
|
2023-01-08 20:27:26 +00:00
|
|
|
func magnetize():
|
|
|
|
is_magnetized = true
|
|
|
|
emit_signal("magnetized")
|
2023-01-08 08:22:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _physics_process(delta):
|
2023-01-08 20:27:26 +00:00
|
|
|
if is_magnetized and target != null:
|
2023-01-08 12:47:44 +00:00
|
|
|
var direction = Singletons.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):
|
2023-01-08 12:47:44 +00:00
|
|
|
if body is Player:
|
2023-01-08 20:27:26 +00:00
|
|
|
magnetize()
|