mirror of
https://github.com/Steffo99/pineapple-surf.git
synced 2024-11-25 09:14:18 +00:00
MoveTowardsPlayer
: Use a target instead of the direct parent
This commit is contained in:
parent
b97916bedc
commit
c9d4df4a86
2 changed files with 6 additions and 5 deletions
|
@ -1,9 +1,9 @@
|
||||||
extends Node
|
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!
|
# Must be BELOW the player node to work!
|
||||||
@onready var parent: RigidBody3D = get_parent()
|
|
||||||
@onready var magnet_area: Area3D = $MagnetArea
|
@onready var magnet_area: Area3D = $MagnetArea
|
||||||
@onready var player: CharacterBody3D = get_tree().root.find_child("Player", true, false)
|
@onready var player: CharacterBody3D = get_tree().root.find_child("Player", true, false)
|
||||||
|
|
||||||
|
@ -17,9 +17,9 @@ func capture():
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
if captured:
|
if captured:
|
||||||
var direction = player.position - parent.position
|
var direction = player.position - target.position
|
||||||
var force = direction.normalized() * force_multiplier * delta
|
var force = direction.normalized() * force_multiplier * delta
|
||||||
parent.apply_force(force)
|
target.apply_force(force)
|
||||||
|
|
||||||
|
|
||||||
func _on_magnet_area_body_entered(body: Node3D):
|
func _on_magnet_area_body_entered(body: Node3D):
|
||||||
|
|
|
@ -22,9 +22,10 @@ shape = SubResource("CylinderShape3D_t5bjw")
|
||||||
|
|
||||||
[node name="PineappleMesh" parent="." instance=ExtResource("1_ndmmp")]
|
[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")
|
script = ExtResource("2_d3itl")
|
||||||
force_multiplier = 1250.0
|
force_multiplier = 1250.0
|
||||||
|
target = NodePath("..")
|
||||||
|
|
||||||
[node name="MagnetArea" type="Area3D" parent="MoveTowardsPlayer"]
|
[node name="MagnetArea" type="Area3D" parent="MoveTowardsPlayer"]
|
||||||
collision_layer = 0
|
collision_layer = 0
|
||||||
|
|
Loading…
Reference in a new issue