Skip to content

Commit

Permalink
Added sounds, fixed monster confusion!
Browse files Browse the repository at this point in the history
  • Loading branch information
abc-is-here committed Aug 31, 2024
1 parent cbf0241 commit c85da98
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 9 deletions.
21 changes: 20 additions & 1 deletion scenes/monster.tscn
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
[gd_scene load_steps=7 format=3 uid="uid://dx1ux81apl4g6"]
[gd_scene load_steps=12 format=3 uid="uid://dx1ux81apl4g6"]

[ext_resource type="Script" path="res://scripts/monster.gd" id="1_ydtmb"]
[ext_resource type="AudioStream" uid="uid://cmuk3a77cik60" path="res://sounds/foot-step-snow-1-189869.mp3" id="2_8qu2w"]
[ext_resource type="Material" uid="uid://dlkdulrqiau3f" path="res://material/wall.tres" id="2_qbxnp"]
[ext_resource type="AudioStream" uid="uid://w2ogp66t7b0m" path="res://sounds/068289_jumpscare-sound-47224.mp3" id="3_apo40"]
[ext_resource type="AudioStream" uid="uid://d0rlsdjbb4gwv" path="res://sounds/foot-step-snow-4-189865.mp3" id="3_hmxcy"]
[ext_resource type="AudioStream" uid="uid://c21a3yeghxlsv" path="res://sounds/foot-step-snow-13-189871.mp3" id="4_d0hs4"]
[ext_resource type="Script" path="res://scripts/enemy_raycast.gd" id="4_f1cmn"]
[ext_resource type="Script" path="res://scripts/chase_player.gd" id="5_cifo2"]
[ext_resource type="AudioStream" uid="uid://js5yn0gnsy8m" path="res://sounds/chase-120950.mp3" id="9_8fv5g"]

[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_47k48"]

Expand All @@ -12,6 +17,7 @@
[node name="monster" type="CharacterBody3D" groups=["monster"]]
script = ExtResource("1_ydtmb")
scene_name = "death"
walk_footsteps = Array[AudioStream]([ExtResource("2_8qu2w"), ExtResource("3_hmxcy"), ExtResource("4_d0hs4")])

[node name="CollisionShape3D" type="CollisionShape3D" parent="."]
shape = SubResource("CapsuleShape3D_47k48")
Expand Down Expand Up @@ -44,5 +50,18 @@ transform = Transform3D(2, 0, 0, 0, -8.74228e-08, -2, 0, 2, -8.74228e-08, 0, 0,
collision_mask = 3
script = ExtResource("4_f1cmn")

[node name="RayCast3D2" type="RayCast3D" parent="."]
transform = Transform3D(10, 0, 0, 0, -4.37114e-07, -10, 0, 10, -4.37114e-07, 0, 0.559829, -0.489382)
collision_mask = 3
script = ExtResource("5_cifo2")

[node name="footsteps" type="AudioStreamPlayer3D" parent="."]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.629689, 0)
max_db = 6.0
max_distance = 20.0

[node name="chase_music" type="AudioStreamPlayer" parent="."]
stream = ExtResource("9_8fv5g")

[connection signal="target_reached" from="NavigationAgent3D" to="." method="pick_new_destination"]
[connection signal="velocity_computed" from="NavigationAgent3D" to="." method="_on_navigation_agent_3d_velocity_computed"]
8 changes: 8 additions & 0 deletions scripts/chase_player.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extends RayCast3D

func _process(delta: float) -> void:
if is_colliding():
var hit = get_collider()
if hit.name == "Player" && !get_parent().chasing:
get_parent().chasing == true
get_parent().SPEED = 5.0
37 changes: 29 additions & 8 deletions scripts/monster.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
extends CharacterBody3D

var SPEED = 4.0
var SPEED = 2.5
var player
var caught = false
var distance: float
Expand All @@ -10,8 +10,9 @@ var jumpscare_time = 2
var rng
var current_destination
var chasing = false

var able_to_pick = false
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
@export var walk_footsteps: Array[AudioStream]

func _ready() -> void:
rng = RandomNumberGenerator.new()
Expand All @@ -20,17 +21,38 @@ func _ready() -> void:
current_destination = destination[random_dest]

func pick_new_destination():
if chasing == false:
if chasing == false && able_to_pick == false && distance<=1:
able_to_pick = true
SPEED = 0
var wait_time = rng.randf_range(3.0, 10.0)
await get_tree().create_timer(wait_time, false).timeout
var random_dest = rng.randi_range(0, destination.size() - 1)
current_destination = destination[random_dest]
if distance<=1:
var random_dest = rng.randi_range(0, destination.size() - 1)
SPEED = 2.5
current_destination = destination[random_dest]
able_to_pick = false

func _process(delta: float) -> void:
if chasing == false:
if chasing == true && !$chase_music.playing:
$chase_music.play()
if chasing == false && $chase_music.playing:
$chase_music.stop()

if chasing == false && SPEED>0:
if !$footsteps.playing:
var num = rng.randi_range(0, walk_footsteps.size() - 1)
$footsteps.stream = walk_footsteps[num]
$footsteps.play()

distance = current_destination.global_transform.origin.distance_to(global_transform.origin)
update_target_location(current_destination.global_transform.origin)
if chasing:
if chasing && SPEED>0:
if !$footsteps.playing:
var num = rng.randi_range(0, walk_footsteps.size() - 1)
$footsteps.stream = walk_footsteps[num]
$footsteps.play()
update_target_location(player.global_transform.origin)
distance = player.global_transform.origin.distance_to(global_transform.origin)

func _physics_process(delta: float) -> void:
get_tree().create_timer(20.0, false).timeout
Expand All @@ -44,7 +66,6 @@ func _physics_process(delta: float) -> void:
var look_dir = atan2(-velocity.x, -velocity.z)
rotation.y = look_dir
if chasing:
distance = player.global_transform.origin.distance_to(global_transform.origin)
if distance <=2 && caught == false:
player.visible = false
if !$jumpscare.playing:
Expand Down
Binary file added sounds/chase-120950.mp3
Binary file not shown.
19 changes: 19 additions & 0 deletions sounds/chase-120950.mp3.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[remap]

importer="mp3"
type="AudioStreamMP3"
uid="uid://js5yn0gnsy8m"
path="res://.godot/imported/chase-120950.mp3-74030b1558015b31d3800b26514b47ec.mp3str"

[deps]

source_file="res://sounds/chase-120950.mp3"
dest_files=["res://.godot/imported/chase-120950.mp3-74030b1558015b31d3800b26514b47ec.mp3str"]

[params]

loop=true
loop_offset=0.0
bpm=0.0
beat_count=0
bar_beats=4
Binary file added sounds/death.mp3
Binary file not shown.
19 changes: 19 additions & 0 deletions sounds/death.mp3.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[remap]

importer="mp3"
type="AudioStreamMP3"
uid="uid://3t0ei4ekgkcy"
path="res://.godot/imported/death.mp3-90b5bf50eb2bd98e7645e11246467b93.mp3str"

[deps]

source_file="res://sounds/death.mp3"
dest_files=["res://.godot/imported/death.mp3-90b5bf50eb2bd98e7645e11246467b93.mp3str"]

[params]

loop=false
loop_offset=0
bpm=0
beat_count=0
bar_beats=4
Binary file added sounds/jumpscare-94984.mp3
Binary file not shown.
19 changes: 19 additions & 0 deletions sounds/jumpscare-94984.mp3.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[remap]

importer="mp3"
type="AudioStreamMP3"
uid="uid://csqo67dhxbl3j"
path="res://.godot/imported/jumpscare-94984.mp3-37276028d252d0e47be70dbf650d579c.mp3str"

[deps]

source_file="res://sounds/jumpscare-94984.mp3"
dest_files=["res://.godot/imported/jumpscare-94984.mp3-37276028d252d0e47be70dbf650d579c.mp3str"]

[params]

loop=false
loop_offset=0
bpm=0
beat_count=0
bar_beats=4

0 comments on commit c85da98

Please sign in to comment.