1
Fork 0
mirror of https://github.com/Steffo99/pineapple-surf.git synced 2024-11-29 03:04:17 +00:00
pineapple-surf/island/MoveTowardsPlayer.gd

28 lines
601 B
GDScript3
Raw Normal View History

extends Node
2023-01-08 20:27:26 +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 20:27:26 +00:00
@onready var target: RigidBody3D = get_node(target_path)
2023-01-08 20:27:26 +00:00
signal magnetized()
2023-01-08 20:27:26 +00:00
func magnetize():
is_magnetized = true
emit_signal("magnetized")
func _physics_process(delta):
2023-01-08 20:27:26 +00:00
if is_magnetized and target != null:
var direction = Singletons.player.position - target.position
var force = direction.normalized() * force_multiplier * delta
target.apply_force(force)
func _on_magnet_area_body_entered(body: Node3D):
if body is Player:
2023-01-08 20:27:26 +00:00
magnetize()