mirror of
https://github.com/Steffo99/pineapple-surf.git
synced 2024-11-29 03:04:17 +00:00
Refactor Pineapple scene
This commit is contained in:
parent
eda71d785f
commit
040aee2f15
5 changed files with 96 additions and 54 deletions
25
island/CollectibleByPlayer.gd
Normal file
25
island/CollectibleByPlayer.gd
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
extends Node3D
|
||||||
|
|
||||||
|
|
||||||
|
@export_node_path(RigidBody3D) var target_path: NodePath
|
||||||
|
@onready var sound: AudioStreamPlayer3D = $CollectSound
|
||||||
|
var is_collected := false
|
||||||
|
|
||||||
|
@onready var target: RigidBody3D = get_node(target_path)
|
||||||
|
|
||||||
|
signal collected()
|
||||||
|
|
||||||
|
|
||||||
|
func collect():
|
||||||
|
is_collected = true
|
||||||
|
target.visible = false
|
||||||
|
sound.play()
|
||||||
|
emit_signal("collected")
|
||||||
|
await get_tree().create_timer(1).timeout
|
||||||
|
target.queue_free()
|
||||||
|
|
||||||
|
|
||||||
|
func _on_collect_area_body_entered(body: Node3D):
|
||||||
|
if body is Player:
|
||||||
|
collect()
|
||||||
|
|
27
island/CollectibleByPlayer.tscn
Normal file
27
island/CollectibleByPlayer.tscn
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
[gd_scene load_steps=4 format=3 uid="uid://ci0hy0d4d1476"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://island/CollectibleByPlayer.gd" id="1_grwn8"]
|
||||||
|
[ext_resource type="AudioStream" uid="uid://cykcqgvvh2lrc" path="res://assets/collect.wav" id="2_0trxg"]
|
||||||
|
|
||||||
|
[sub_resource type="CylinderShape3D" id="CylinderShape3D_0qal3"]
|
||||||
|
height = 1.4
|
||||||
|
radius = 0.7
|
||||||
|
|
||||||
|
[node name="CollectibleByPlayer" type="Node3D"]
|
||||||
|
script = ExtResource("1_grwn8")
|
||||||
|
|
||||||
|
[node name="CollectSound" type="AudioStreamPlayer3D" parent="."]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.5, 0.1, 0.5)
|
||||||
|
stream = ExtResource("2_0trxg")
|
||||||
|
attenuation_filter_cutoff_hz = 20500.0
|
||||||
|
|
||||||
|
[node name="CollectArea" type="Area3D" parent="."]
|
||||||
|
collision_layer = 0
|
||||||
|
collision_mask = 4
|
||||||
|
monitorable = false
|
||||||
|
|
||||||
|
[node name="Shape" type="CollisionShape3D" parent="CollectArea"]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
|
||||||
|
shape = SubResource("CylinderShape3D_0qal3")
|
||||||
|
|
||||||
|
[connection signal="body_entered" from="CollectArea" to="." method="_on_collect_area_body_entered"]
|
|
@ -1,23 +1,22 @@
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
|
|
||||||
@export var force_multiplier: float
|
@export var force_multiplier: float
|
||||||
@export var target: RigidBody3D
|
@export_node_path(RigidBody3D) var target_path: NodePath
|
||||||
@export var capture_radius: float = 1.5
|
@export var is_magnetized := false
|
||||||
|
|
||||||
@onready var magnet_area: Area3D = $MagnetArea
|
@onready var target: RigidBody3D = get_node(target_path)
|
||||||
@onready var capture_area: Area3D = $CaptureArea
|
|
||||||
@onready var pop: AudioStreamPlayer3D = $"../Pop"
|
|
||||||
@onready var mesh: MeshInstance3D = $"../PineappleMesh"
|
|
||||||
|
|
||||||
var captured = false
|
signal magnetized()
|
||||||
|
|
||||||
|
|
||||||
func capture():
|
func magnetize():
|
||||||
captured = true
|
is_magnetized = true
|
||||||
|
emit_signal("magnetized")
|
||||||
|
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
if captured:
|
if is_magnetized and target != null:
|
||||||
var direction = Singletons.player.position - target.position
|
var direction = Singletons.player.position - target.position
|
||||||
var force = direction.normalized() * force_multiplier * delta
|
var force = direction.normalized() * force_multiplier * delta
|
||||||
target.apply_force(force)
|
target.apply_force(force)
|
||||||
|
@ -25,12 +24,4 @@ func _physics_process(delta):
|
||||||
|
|
||||||
func _on_magnet_area_body_entered(body: Node3D):
|
func _on_magnet_area_body_entered(body: Node3D):
|
||||||
if body is Player:
|
if body is Player:
|
||||||
print("Player captured pickup!")
|
magnetize()
|
||||||
capture()
|
|
||||||
|
|
||||||
|
|
||||||
func _on_capture_area_body_entered(body: Node3D) -> void:
|
|
||||||
mesh.visible = false
|
|
||||||
pop.play()
|
|
||||||
await get_tree().create_timer(1).timeout
|
|
||||||
target.queue_free()
|
|
||||||
|
|
22
island/MoveTowardsPlayer.tscn
Normal file
22
island/MoveTowardsPlayer.tscn
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
[gd_scene load_steps=3 format=3 uid="uid://cvou86mnmtloe"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://island/MoveTowardsPlayer.gd" id="1_bpw63"]
|
||||||
|
|
||||||
|
[sub_resource type="CylinderShape3D" id="CylinderShape3D_qg6sr"]
|
||||||
|
height = 6.0
|
||||||
|
radius = 3.0
|
||||||
|
|
||||||
|
[node name="MoveTowardsPlayer" type="Node3D" node_paths=PackedStringArray("target")]
|
||||||
|
script = ExtResource("1_bpw63")
|
||||||
|
force_multiplier = 1250.0
|
||||||
|
target = NodePath("..")
|
||||||
|
|
||||||
|
[node name="MagnetArea" type="Area3D" parent="."]
|
||||||
|
collision_layer = 0
|
||||||
|
monitorable = false
|
||||||
|
|
||||||
|
[node name="Shape" type="CollisionShape3D" parent="MagnetArea"]
|
||||||
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
|
||||||
|
shape = SubResource("CylinderShape3D_qg6sr")
|
||||||
|
|
||||||
|
[connection signal="body_entered" from="MagnetArea" to="." method="_on_magnet_area_body_entered"]
|
|
@ -1,22 +1,15 @@
|
||||||
[gd_scene load_steps=8 format=3 uid="uid://v7bv81krh12e"]
|
[gd_scene load_steps=7 format=3 uid="uid://v7bv81krh12e"]
|
||||||
|
|
||||||
[ext_resource type="PackedScene" uid="uid://bwwpi0itor6cw" path="res://island/PineappleMesh.tscn" id="1_ndmmp"]
|
[ext_resource type="PackedScene" uid="uid://bwwpi0itor6cw" path="res://island/PineappleMesh.tscn" id="1_ndmmp"]
|
||||||
[ext_resource type="Script" path="res://island/MoveTowardsPlayer.gd" id="2_d3itl"]
|
|
||||||
[ext_resource type="AudioStream" uid="uid://lkftwgdun745" path="res://assets/pop.wav" id="3_b3ttd"]
|
[ext_resource type="AudioStream" uid="uid://lkftwgdun745" path="res://assets/pop.wav" id="3_b3ttd"]
|
||||||
[ext_resource type="Script" path="res://island/Pop.gd" id="4_rn5e2"]
|
[ext_resource type="Script" path="res://island/Pop.gd" id="4_rn5e2"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://cvou86mnmtloe" path="res://island/MoveTowardsPlayer.tscn" id="4_xnsun"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://ci0hy0d4d1476" path="res://island/CollectibleByPlayer.tscn" id="5_yps0c"]
|
||||||
|
|
||||||
[sub_resource type="CylinderShape3D" id="CylinderShape3D_l6rok"]
|
[sub_resource type="CylinderShape3D" id="CylinderShape3D_ax3vd"]
|
||||||
height = 0.9
|
height = 0.9
|
||||||
radius = 0.3
|
radius = 0.3
|
||||||
|
|
||||||
[sub_resource type="CylinderShape3D" id="CylinderShape3D_qf6hb"]
|
|
||||||
height = 6.0
|
|
||||||
radius = 3.0
|
|
||||||
|
|
||||||
[sub_resource type="CylinderShape3D" id="CylinderShape3D_w04xf"]
|
|
||||||
height = 1.4
|
|
||||||
radius = 0.7
|
|
||||||
|
|
||||||
[node name="Pineapple" type="RigidBody3D"]
|
[node name="Pineapple" type="RigidBody3D"]
|
||||||
collision_layer = 2
|
collision_layer = 2
|
||||||
collision_mask = 5
|
collision_mask = 5
|
||||||
|
@ -25,37 +18,21 @@ linear_damp = 1.0
|
||||||
|
|
||||||
[node name="Shape" type="CollisionShape3D" parent="."]
|
[node name="Shape" type="CollisionShape3D" parent="."]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.45, 0)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.45, 0)
|
||||||
shape = SubResource("CylinderShape3D_l6rok")
|
shape = SubResource("CylinderShape3D_ax3vd")
|
||||||
|
|
||||||
[node name="PineappleMesh" parent="." instance=ExtResource("1_ndmmp")]
|
[node name="PineappleMesh" parent="." instance=ExtResource("1_ndmmp")]
|
||||||
|
|
||||||
[node name="Pop" type="AudioStreamPlayer3D" parent="."]
|
[node name="PopSound" type="AudioStreamPlayer3D" parent="."]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.5, 0.1, 0.5)
|
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.5, 0.1, 0.5)
|
||||||
stream = ExtResource("3_b3ttd")
|
stream = ExtResource("3_b3ttd")
|
||||||
attenuation_filter_cutoff_hz = 20500.0
|
attenuation_filter_cutoff_hz = 20500.0
|
||||||
script = ExtResource("4_rn5e2")
|
script = ExtResource("4_rn5e2")
|
||||||
|
|
||||||
[node name="MoveTowardsPlayer" type="Node3D" parent="." node_paths=PackedStringArray("target")]
|
[node name="MoveTowardsPlayer" parent="." instance=ExtResource("4_xnsun")]
|
||||||
script = ExtResource("2_d3itl")
|
target_path = NodePath("..")
|
||||||
force_multiplier = 1250.0
|
|
||||||
target = NodePath("..")
|
|
||||||
|
|
||||||
[node name="MagnetArea" type="Area3D" parent="MoveTowardsPlayer"]
|
[node name="CollectibleByPlayer" parent="." instance=ExtResource("5_yps0c")]
|
||||||
collision_layer = 0
|
target_path = NodePath("..")
|
||||||
monitorable = false
|
|
||||||
|
|
||||||
[node name="Shape" type="CollisionShape3D" parent="MoveTowardsPlayer/MagnetArea"]
|
[editable path="MoveTowardsPlayer"]
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
|
[editable path="CollectibleByPlayer"]
|
||||||
shape = SubResource("CylinderShape3D_qf6hb")
|
|
||||||
|
|
||||||
[node name="CaptureArea" type="Area3D" parent="MoveTowardsPlayer"]
|
|
||||||
collision_layer = 0
|
|
||||||
collision_mask = 4
|
|
||||||
monitorable = false
|
|
||||||
|
|
||||||
[node name="Shape" type="CollisionShape3D" parent="MoveTowardsPlayer/CaptureArea"]
|
|
||||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
|
|
||||||
shape = SubResource("CylinderShape3D_w04xf")
|
|
||||||
|
|
||||||
[connection signal="body_entered" from="MoveTowardsPlayer/MagnetArea" to="MoveTowardsPlayer" method="_on_magnet_area_body_entered"]
|
|
||||||
[connection signal="body_entered" from="MoveTowardsPlayer/CaptureArea" to="MoveTowardsPlayer" method="_on_capture_area_body_entered"]
|
|
||||||
|
|
Loading…
Reference in a new issue