From: Eduardo Date: Fri, 9 Feb 2024 23:58:58 +0000 (+0100) Subject: change noise production based on speed (running, walking or squating) X-Git-Url: http://git.edufdez.es/?a=commitdiff_plain;h=8691522b065b9797e72c0b27775ddf437003c312;p=ScaryGame.git change noise production based on speed (running, walking or squating) --- diff --git a/levels/unicorn_level/unicorn_map.tscn b/levels/unicorn_level/unicorn_map.tscn index 8216467..5767ea1 100644 --- a/levels/unicorn_level/unicorn_map.tscn +++ b/levels/unicorn_level/unicorn_map.tscn @@ -1798,6 +1798,8 @@ transform = Transform3D(1, 0, 3.72529e-09, 0, 1, 0, 7.45058e-09, 0, 1, 0, 2.1784 [node name="Player" parent="." instance=ExtResource("1_yhk1e")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -143.826, 0, -132.995) +squating_noise_mod = 0.5 +running_noise_mod = 1.75 [node name="BaseEnemy" parent="." node_paths=PackedStringArray("player") instance=ExtResource("6_os3o0")] transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -229.93, 0, -72.7142) diff --git a/player/Player.gd b/player/Player.gd index 6908a9d..6630775 100644 --- a/player/Player.gd +++ b/player/Player.gd @@ -7,7 +7,7 @@ extends CharacterBody3D # How fast the player moves in meters per second. @export var speed := 5 @export_range(0, 2) var squating_speed_mod: float = .5 -@export_range(0, 2) var runnig_speed_mod: float = 1.5 +@export_range(0, 2) var running_speed_mod: float = 1.5 # The downward acceleration when in the air, in meters per second squared. @export var fall_acceleration := 10 @@ -15,7 +15,7 @@ extends CharacterBody3D @onready var camera := $Camera3D var target_velocity := Vector3.ZERO -var noise: int = 0 +var noise: float = 0 const squat_position := 0.6 # Position to which the camera moves when squatting const stand_position := 1.7 # Position to which the camera moves when standing @@ -27,6 +27,7 @@ var is_squatting := false func _physics_process(delta): var direction := Vector3.ZERO var speed_mod: float = 1 + var noise_mod: float = 1 if Input.is_action_just_pressed("squat"): is_squatting = true @@ -38,10 +39,12 @@ func _physics_process(delta): elif not is_squatting and camera.position.y < stand_position: camera.translate(Vector3(0, move_speed * delta, 0)) - if Input.is_action_pressed("run"): - speed_mod = runnig_speed_mod if Input.is_action_pressed("squat"): speed_mod = squating_speed_mod + noise_mod = squating_noise_mod + elif Input.is_action_pressed("run"): + speed_mod = running_speed_mod + noise_mod = running_noise_mod if Input.is_action_pressed("move_right"): direction += transform.basis.x @@ -58,7 +61,8 @@ func _physics_process(delta): # if movement make some noise if randf() > .95: - noise = clamp(noise + 1, 0, 9) + var add_noise = 1 * noise_mod + noise = clamp(noise + add_noise, 0, 9) set_meta("noise", noise) target_velocity.x = direction.x * speed * speed_mod