From c9d4df4a86fd77520ab95fa92c1bf1faad5d4de0 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 8 Jan 2023 10:11:38 +0100 Subject: [PATCH] `MoveTowardsPlayer`: Use a target instead of the direct parent --- island/MoveTowardsPlayer.gd | 8 ++++---- island/Pineapple.tscn | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) 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