Skip to content

Commit 5bc518f

Browse files
Merge branch 'develop'
2 parents f128ffa + 8e59df1 commit 5bc518f

File tree

9 files changed

+259
-47
lines changed

9 files changed

+259
-47
lines changed

abilities/crouch_ability_3d.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class_name CrouchAbility3D
1818
## Collider height when crouch deactived
1919
@export var default_height := 2.0
2020

21+
var crouch_factor : float
2122

2223
## Applies slow if crouch is enabled
2324
func get_speed_modifier() -> float:
@@ -33,4 +34,5 @@ func apply(velocity: Vector3, speed : float, is_on_floor : bool, direction : Vec
3334
elif not head_check.is_colliding():
3435
collision.shape.height += delta * 8
3536
collision.shape.height = clamp(collision.shape.height , height_in_crouch, default_height)
37+
crouch_factor = (default_height - height_in_crouch) - (collision.shape.height - height_in_crouch)/ (default_height - height_in_crouch)
3638
return velocity

audios/audio_interact.gd

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
extends Resource
2+
class_name AudioInteract
3+
4+
## Resource that stores data by controller actions.
5+
6+
## Jump Audio
7+
@export var jump_audio : AudioStream
8+
9+
## Landed Audio
10+
@export var landed_audio : AudioStream
11+
12+
## Step Audios
13+
@export var step_audios: Array[AudioStream]
14+
15+
16+
## Get random step audio from list
17+
func random_step() -> AudioStream:
18+
return step_audios[randi() % step_audios.size()]

audios/character_audios.tscn

Lines changed: 40 additions & 0 deletions
Large diffs are not rendered by default.

audios/character_audios_3d.gd

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
extends Node3D
2+
class_name CharacterAudios3D
3+
4+
## Script that plays sounds based on player actions.
5+
## Using an [AudioInteract] array synchronized with physic_materials array to
6+
## identify different sound structures for each type of physical material.
7+
8+
@onready var step_stream: AudioStreamPlayer3D = get_node(NodePath("Step"))
9+
@onready var land_stream: AudioStreamPlayer3D = get_node(NodePath("Land"))
10+
@onready var jump_stream: AudioStreamPlayer3D = get_node(NodePath("Jump"))
11+
@onready var crouch_stream: AudioStreamPlayer3D = get_node(NodePath("Crouch"))
12+
@onready var uncrouch_stream: AudioStreamPlayer3D = get_node(NodePath("Uncrouch"))
13+
@onready var raycast: RayCast3D = get_node(NodePath("Detect Ground"))
14+
@onready var character_body: CharacterBody3D = get_node(NodePath(".."))
15+
@onready var character_controller: CharacterController3D = get_node(NodePath(".."))
16+
17+
## Default audio interact used
18+
@export var audio_interact : Resource
19+
20+
## List of [PhysicsMaterial] synchronized with the [AudioInteract] list
21+
@export var physic_materials : Array[PhysicsMaterial]
22+
23+
## List of [AudioInteract] synchronized with the [PhysicsMaterial] list
24+
@export var audio_interacts : Array[Resource]
25+
26+
## Specific case of audio interact that occurs when we are in the water
27+
@export var water_audio_interact : Resource
28+
29+
func _ready():
30+
pass
31+
character_controller.stepped.connect(_on_controller_stepped.bind())
32+
character_controller.crouched.connect(_on_controller_crouched.bind())
33+
character_controller.jumped.connect(_on_controller_jumped.bind())
34+
character_controller.landed.connect(_on_controller_landed.bind())
35+
character_controller.uncrouched.connect(_on_controller_uncrouched.bind())
36+
character_controller.entered_the_water.connect(_on_controller_entered_the_water.bind())
37+
character_controller.exit_the_water.connect(_on_controller_exit_the_water.bind())
38+
39+
func _on_controller_jumped():
40+
jump_stream.stream = audio_interact.jump_audio
41+
jump_stream.play()
42+
43+
44+
func _on_controller_landed():
45+
_get_audio_interact()
46+
land_stream.stream = audio_interact.landed_audio
47+
land_stream.play()
48+
49+
50+
func _on_controller_stepped():
51+
var collision = raycast.get_collider()
52+
_get_audio_interact_of_object(collision)
53+
step_stream.stream = audio_interact.random_step()
54+
step_stream.play()
55+
56+
57+
func _get_audio_interact():
58+
var k_col = character_body.get_last_slide_collision()
59+
if k_col != null:
60+
var collision = k_col.get_collider(0)
61+
_get_audio_interact_of_object(collision)
62+
63+
64+
func _get_audio_interact_of_object(collision):
65+
if character_controller.is_on_water():
66+
audio_interact = water_audio_interact
67+
return
68+
if !collision:
69+
return
70+
if not "physics_material_override" in collision:
71+
return
72+
var mat = collision.physics_material_override
73+
if mat:
74+
var i = physic_materials.rfind(mat)
75+
if i != -1:
76+
audio_interact = audio_interacts[i]
77+
78+
79+
func _on_controller_crouched():
80+
crouch_stream.play()
81+
82+
83+
func _on_controller_uncrouched():
84+
uncrouch_stream.play()
85+
86+
87+
func _on_controller_entered_the_water():
88+
audio_interact = water_audio_interact
89+
land_stream.stream = audio_interact.landed_audio
90+
land_stream.play()
91+
92+
93+
func _on_controller_exit_the_water():
94+
jump_stream.stream = audio_interact.jump_audio
95+
jump_stream.play()

core/character_controller_3d.gd

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -68,74 +68,74 @@ signal stopped_floating
6868
## Controller Gravity Multiplier
6969
## The higher the number, the faster the controller will fall to the ground and
7070
## your jump will be shorter.
71-
@export var gravity_multiplier := 3.0
71+
@export var gravity_multiplier : float = 3.0
7272

7373
## Controller base speed
7474
## Note: this speed is used as a basis for abilities to multiply their
7575
## respective values, changing it will have consequences on [b]all abilities[/b]
7676
## that use velocity.
77-
@export var speed := 10
77+
@export var speed : float = 10.0
7878

7979
## Time for the character to reach full speed
80-
@export var acceleration := 8
80+
@export var acceleration : float = 8.0
8181

8282
## Time for the character to stop walking
83-
@export var deceleration := 10
83+
@export var deceleration : float = 10.0
8484

8585
## Sets control in the air
86-
@export var air_control := 0.3
86+
@export var air_control : float = 0.3
8787

8888

8989
@export_group("Sprint")
9090

9191
## Speed to be multiplied when active the ability
92-
@export var sprint_speed_multiplier := 1.6
92+
@export var sprint_speed_multiplier : float = 1.6
9393

9494

9595
@export_group("Footsteps")
9696

9797
## Maximum counter value to be computed one step
98-
@export var step_lengthen := 0.7
98+
@export var step_lengthen : float = 0.7
9999

100100
## Value to be added to compute a step, each frame that the character is walking this value
101101
## is added to a counter
102-
@export var step_interval := 6.0
102+
@export var step_interval : float = 6.0
103103

104104

105105
@export_group("Crouch")
106106

107107
## Collider height when crouch actived
108-
@export var height_in_crouch := 1.0
108+
@export var height_in_crouch : float = 1.0
109109

110110
## Speed multiplier when crouch is actived
111-
@export var crouch_speed_multiplier := 0.7
111+
@export var crouch_speed_multiplier : float = 0.7
112112

113113

114114
@export_group("Jump")
115115

116116
## Jump/Impulse height
117-
@export var jump_height := 10
117+
@export var jump_height : float = 10.0
118118

119119

120120
@export_group("Fly")
121121

122122
## Speed multiplier when fly mode is actived
123-
@export var fly_mode_speed_modifier := 2
123+
@export var fly_mode_speed_modifier : float = 2.0
124124

125125

126126
@export_group("Swim")
127127

128128
## Minimum height for [CharacterController3D] to be completely submerged in water.
129-
@export var submerged_height := 0.36
129+
@export var submerged_height : float = 0.36
130130

131131
## Minimum height for [CharacterController3D] to be float in water.
132-
@export var floating_height := 0.75
132+
@export var floating_height : float = 0.75
133133

134134
## Speed multiplier when floating water
135-
@export var on_water_speed_multiplier := 0.75
135+
@export var on_water_speed_multiplier : float = 0.75
136136

137137
## Speed multiplier when submerged water
138-
@export var submerged_speed_multiplier := 0.5
138+
@export var submerged_speed_multiplier : float = 0.5
139139

140140

141141
@export_group("Abilities")
@@ -155,7 +155,7 @@ var _step_cycle : float = 0
155155
var _next_step : float = 0
156156

157157
## Character controller horizontal speed.
158-
var _horizontal_velocity
158+
var _horizontal_velocity : Vector3
159159

160160
## Base transform node to direct player movement
161161
## Used to differentiate fly mode/swim moves from regular character movement.
@@ -189,7 +189,7 @@ var _direction_base_node : Node3D
189189
@onready var swim_ability: SwimAbility3D = get_node(NodePath("Swim Ability 3D"))
190190

191191
## Stores normal speed
192-
@onready var _normal_speed: int = speed
192+
@onready var _normal_speed : float = speed
193193

194194
## True if in the last frame it was on the ground
195195
var _last_is_on_floor := false
@@ -220,7 +220,7 @@ func move(_delta: float, input_axis := Vector2.ZERO, input_jump := false, input_
220220
jump_ability.set_active(input_jump and is_on_floor() and not head_check.is_colliding())
221221
walk_ability.set_active(not is_fly_mode() and not swim_ability.is_floating())
222222
crouch_ability.set_active(input_crouch and is_on_floor() and not is_floating() and not is_submerged() and not is_fly_mode())
223-
sprint_ability.set_active(input_sprint and is_on_floor() and input_axis.x >= 0.5 and !is_crouching() and not is_fly_mode() and not swim_ability.is_floating() and not swim_ability.is_submerged())
223+
sprint_ability.set_active(input_sprint and is_on_floor() and input_axis.y >= 0.5 and !is_crouching() and not is_fly_mode() and not swim_ability.is_floating() and not swim_ability.is_submerged())
224224

225225
var multiplier = 1.0
226226
for ability in _abilities:
@@ -321,7 +321,7 @@ func _start_variables():
321321

322322
func _check_landed():
323323
if is_on_floor() and not _last_is_on_floor:
324-
emit_signal("landed")
324+
_on_landed()
325325
_reset_step()
326326
_last_is_on_floor = is_on_floor()
327327

@@ -334,13 +334,13 @@ func _check_step(_delta):
334334
func _direction_input(input : Vector2, input_down : bool, input_up : bool, aim_node : Node3D) -> Vector3:
335335
_direction = Vector3()
336336
var aim = aim_node.get_global_transform().basis
337-
if input.x >= 0.5:
337+
if input.y >= 0.5:
338338
_direction -= aim.z
339-
if input.x <= -0.5:
340-
_direction += aim.z
341339
if input.y <= -0.5:
340+
_direction += aim.z
341+
if input.x <= -0.5:
342342
_direction -= aim.x
343-
if input.y >= 0.5:
343+
if input.x >= 0.5:
344344
_direction += aim.x
345345
# NOTE: For free-flying and swimming movements
346346
if is_fly_mode() or is_floating():
@@ -395,6 +395,10 @@ func _on_jumped():
395395
emit_signal("jumped")
396396

397397

398+
func _on_landed():
399+
emit_signal("landed")
400+
401+
398402
func _on_swim_ability_emerged():
399403
emit_signal("emerged")
400404

fps/bob/head_bob.gd

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ var speed : float = 0
5555
var original_position : Vector3
5656

5757
## Store original rotation of head for headbob reference
58-
var original_rotation : Vector3
58+
var original_rotation : Quaternion
5959

6060
## Actual cycle x of step headbob
6161
var cycle_position_x: float = 0
@@ -69,7 +69,7 @@ var step_interval: float = 0
6969

7070
func _ready():
7171
original_position = head.position
72-
original_rotation = head.rotation
72+
original_rotation = head.quaternion
7373

7474

7575
## Setup bob with bob base interval
@@ -96,10 +96,10 @@ func head_bob_process(horizontal_velocity:Vector3, input_axis:Vector2, is_sprint
9696
if is_sprint:
9797
input_axis *= 2
9898
if rotation_to_move:
99-
new_rotation += _head_bob_rotation(input_axis.x, input_axis.y, _delta)
99+
new_rotation += _head_bob_rotation(input_axis.y, input_axis.x, _delta)
100100

101101
head.position = new_position
102-
head.rotation = new_rotation
102+
head.quaternion = new_rotation
103103

104104

105105
## Apply headbob jump
@@ -114,9 +114,10 @@ func reset_cycles():
114114
cycle_position_y = 0
115115

116116

117-
func _head_bob_rotation(x, z, _delta) -> Vector3:
118-
var target_rotation = Vector3(x * angle_limit_for_rotation, 0.0, -z * angle_limit_for_rotation)
119-
return lerp(head.rotation, target_rotation, speed_rotation * _delta)
117+
func _head_bob_rotation(x, z, _delta) -> Quaternion:
118+
var target_rotation : Quaternion
119+
target_rotation.from_euler(Vector3(x * angle_limit_for_rotation, 0.0, -z * angle_limit_for_rotation))
120+
return lerp(head.quaternion, target_rotation, speed_rotation * _delta)
120121

121122

122123
func _do_head_bob(speed: float, delta: float) -> Vector3:

0 commit comments

Comments
 (0)