mirror of
https://github.com/Steffo99/pineapple-surf.git
synced 2024-11-25 17:24:19 +00:00
30 lines
680 B
GDScript3
30 lines
680 B
GDScript3
|
extends Node
|
||
|
|
||
|
@export var force_multiplier: float = 0.0
|
||
|
|
||
|
# Must be BELOW the player node to work!
|
||
|
@onready var parent: RigidBody3D = get_parent()
|
||
|
@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:
|
||
|
var direction = player.position - parent.position
|
||
|
var force = direction.normalized() * force_multiplier * delta
|
||
|
force.y = abs(force.y)
|
||
|
parent.apply_force(force)
|
||
|
|
||
|
|
||
|
func _on_magnet_area_body_entered(body: Node3D):
|
||
|
if body.name == "Player":
|
||
|
print("Player captured pickup!")
|
||
|
capture()
|