1
Fork 0
mirror of https://github.com/Steffo99/pineapple-surf.git synced 2024-11-25 01:04:18 +00:00

Use singleton for Player access and despawn pineapple on Player collision

This commit is contained in:
Ichicoro 2023-01-08 13:47:44 +01:00
parent bf59b1ecd2
commit fb54a67393
5 changed files with 54 additions and 12 deletions

9
Singletons.gd Normal file
View file

@ -0,0 +1,9 @@
extends Node
var player: Player
func _ready() -> void:
pass
func _process(delta: float) -> void:
pass

View file

@ -2,11 +2,12 @@ extends Node
@export var force_multiplier: float
@export var target: RigidBody3D
@export var capture_radius: float = 1.5
# Must be BELOW the player node to work!
@onready var magnet_area: Area3D = $MagnetArea
@onready var player: CharacterBody3D = get_tree().root.find_child("Player", true, false)
@onready var capture_area: Area3D = $CaptureArea
@onready var pop: AudioStreamPlayer3D = $"../Pop"
@onready var mesh: MeshInstance3D = $"../PineappleMesh"
var captured = false
@ -17,12 +18,19 @@ func capture():
func _physics_process(delta):
if captured:
var direction = player.position - target.position
var direction = Singletons.player.position - target.position
var force = direction.normalized() * force_multiplier * delta
target.apply_force(force)
func _on_magnet_area_body_entered(body: Node3D):
if body.name == "Player":
if body is Player:
print("Player captured pickup!")
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()

View file

@ -1,28 +1,40 @@
[gd_scene load_steps=5 format=3 uid="uid://v7bv81krh12e"]
[gd_scene load_steps=8 format=3 uid="uid://v7bv81krh12e"]
[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="Script" path="res://island/Pop.gd" id="4_rn5e2"]
[sub_resource type="CylinderShape3D" id="CylinderShape3D_t5bjw"]
[sub_resource type="CylinderShape3D" id="CylinderShape3D_xodvb"]
height = 0.9
radius = 0.3
[sub_resource type="CylinderShape3D" id="CylinderShape3D_m5gp0"]
[sub_resource type="CylinderShape3D" id="CylinderShape3D_fghe6"]
height = 6.0
radius = 3.0
[sub_resource type="CylinderShape3D" id="CylinderShape3D_j5xpy"]
height = 1.4
radius = 0.7
[node name="Pineapple" type="RigidBody3D"]
collision_layer = 2
collision_mask = 3
collision_mask = 5
lock_rotation = true
linear_damp = 1.0
[node name="Shape" type="CollisionShape3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.45, 0)
shape = SubResource("CylinderShape3D_t5bjw")
shape = SubResource("CylinderShape3D_xodvb")
[node name="PineappleMesh" parent="." instance=ExtResource("1_ndmmp")]
[node name="Pop" type="AudioStreamPlayer3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.5, 0.1, 0.5)
stream = ExtResource("3_b3ttd")
attenuation_filter_cutoff_hz = 20500.0
script = ExtResource("4_rn5e2")
[node name="MoveTowardsPlayer" type="Node3D" parent="." node_paths=PackedStringArray("target")]
script = ExtResource("2_d3itl")
force_multiplier = 1250.0
@ -34,6 +46,16 @@ monitorable = false
[node name="Shape" type="CollisionShape3D" parent="MoveTowardsPlayer/MagnetArea"]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
shape = SubResource("CylinderShape3D_m5gp0")
shape = SubResource("CylinderShape3D_fghe6")
[node name="CaptureArea" type="Area3D" parent="MoveTowardsPlayer"]
collision_layer = 0
collision_mask = 0
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_j5xpy")
[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"]

View file

@ -8,7 +8,7 @@ transparency = 1
shading_mode = 0
albedo_texture = ExtResource("1_x2h5q")
texture_filter = 0
billboard_mode = 2
billboard_mode = 1
[sub_resource type="ArrayMesh" id="ArrayMesh_sjes8"]
_surfaces = [{

View file

@ -118,6 +118,9 @@ fire={
3d_physics/layer_1="Default"
3d_physics/layer_2="Pickups"
3d_physics/layer_3="Player"
3d_physics/layer_4="Terrain"
3d_physics/layer_5="Planted seed"
[rendering]