diff --git a/island/MoveTowardsPlayer.gd b/island/MoveTowardsPlayer.gd index a09584f..9a7f0a6 100644 --- a/island/MoveTowardsPlayer.gd +++ b/island/MoveTowardsPlayer.gd @@ -1,9 +1,9 @@ extends Node -@export var force_multiplier: float = 0.0 +@export var force_multiplier: float +@export var target: RigidBody3D # 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) @@ -17,9 +17,9 @@ func capture(): func _physics_process(delta): if captured: - var direction = player.position - parent.position + var direction = player.position - target.position var force = direction.normalized() * force_multiplier * delta - parent.apply_force(force) + target.apply_force(force) func _on_magnet_area_body_entered(body: Node3D): diff --git a/island/Pineapple.tscn b/island/Pineapple.tscn index bbaa610..a0ae042 100644 --- a/island/Pineapple.tscn +++ b/island/Pineapple.tscn @@ -22,9 +22,10 @@ shape = SubResource("CylinderShape3D_t5bjw") [node name="PineappleMesh" parent="." instance=ExtResource("1_ndmmp")] -[node name="MoveTowardsPlayer" type="Node3D" parent="."] +[node name="MoveTowardsPlayer" type="Node3D" parent="." node_paths=PackedStringArray("target")] script = ExtResource("2_d3itl") force_multiplier = 1250.0 +target = NodePath("..") [node name="MagnetArea" type="Area3D" parent="MoveTowardsPlayer"] collision_layer = 0