Tuning player controller

This commit is contained in:
Spencer Killen 2022-12-11 17:02:57 -07:00
parent ec8dd43b1f
commit 98c0177df2
Signed by: sjkillen
GPG Key ID: F307025B65C860BA
18 changed files with 317 additions and 93 deletions

View File

@ -3,4 +3,6 @@ https://freesound.org/people/davidou/sounds/88449/
https://freesound.org/people/DanJFilms/sounds/529388/
https://freesound.org/people/InspectorJ/sounds/485420/
https://freesound.org/people/deadrobotmusic/sounds/555462/
https://freesound.org/people/saturdaysoundguy/sounds/388019/
https://freesound.org/people/pfranzen/sounds/404327/

View File

@ -0,0 +1,3 @@
source_md5="95d19e3b9268e91ea5d793017c0d222c"
dest_md5="e115a0a023d3922072383d9ef1f22a64"

View File

@ -0,0 +1,3 @@
source_md5="89a03bae3f5ffd821efdace8669d5da0"
dest_md5="9ae0b2b7946df84de32a3125c1171cae"

BIN
godot/assets/audio/388019__saturdaysoundguy__celery-snap.ogg (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -0,0 +1,15 @@
[remap]
importer="ogg_vorbis"
type="AudioStreamOGGVorbis"
path="res://.import/388019__saturdaysoundguy__celery-snap.ogg-3b8796f7d662533b21e4e04538fd4489.oggstr"
[deps]
source_file="res://assets/audio/388019__saturdaysoundguy__celery-snap.ogg"
dest_files=[ "res://.import/388019__saturdaysoundguy__celery-snap.ogg-3b8796f7d662533b21e4e04538fd4489.oggstr" ]
[params]
loop=false
loop_offset=0

Binary file not shown.

View File

@ -0,0 +1,15 @@
[remap]
importer="ogg_vorbis"
type="AudioStreamOGGVorbis"
path="res://.import/404327__pfranzen__male-grunts-and-groans.ogg-bd82bbc47e039725c74abd2d8e837e83.oggstr"
[deps]
source_file="res://assets/audio/404327__pfranzen__male-grunts-and-groans.ogg"
dest_files=[ "res://.import/404327__pfranzen__male-grunts-and-groans.ogg-bd82bbc47e039725c74abd2d8e837e83.oggstr" ]
[params]
loop=false
loop_offset=0

View File

@ -1,50 +0,0 @@
extends Node
var played_jump_sound = false
func jump():
var on_floor = $"../OnFootPhysics/Floor".is_on_floor
var jump_intent = $"../MovementInput".jump_intent
var falling_fast = $"../OnFootPhysics".is_falling_velocity_terminal()
if jump_intent and not on_floor and not played_jump_sound:
$Jump.play()
played_jump_sound = true
elif on_floor and played_jump_sound:
$Jump.stop()
$JumpLanding.play()
played_jump_sound = false
if not on_floor and falling_fast and not $FallingSound.playing:
$FallingSound.play()
$FallingSound.pitch_scale = rand_range(0.5, 1.2)
played_jump_sound = true
elif on_floor:
$FallingSound.stop()
func footsteps():
var on_floor = $"../OnFootPhysics/Floor".is_on_floor
var velocity = $"../MovementInput".input_xz
if not on_floor or velocity.length() == 0:
$Footsteps.stop()
return
if $Footsteps/Timer.time_left > 0.0:
return
$Footsteps.pitch_scale = rand_range(0.9, 1.1)
$Footsteps.play()
var is_sprinting = $"../MovementInput".sprinting
if is_sprinting:
$Footsteps/Timer.start(0.3)
else:
$Footsteps/Timer.start(0.5)
func _process(_delta):
if $"..".is_on_foot():
jump()
footsteps()

View File

@ -0,0 +1,61 @@
extends Node
var played_takeoff: bool = false
var falling: bool = false
func jump():
var phys = $"../OnFootPhysics"
var on_floor = $"../OnFootPhysics/Floor".is_on_floor
var jump_intent = $"../MovementInput".jump_intent
if jump_intent and not on_floor and not played_takeoff:
$Jump.play()
played_takeoff = true
if phys.just_landed:
$Jump.stop()
played_takeoff = false
if $"../OnFootPhysics".velocity.y < -3.0 and not $CameraAnimation.is_playing():
$CameraAnimation.play("jump_landing")
var landing_playing = $JumpLanding.playing or $JumpLandingHardCrunch.playing or $JumpLandingHardOuch.playing
if not landing_playing:
if not phys.just_landed_terminally:
print("a")
$JumpLanding.play()
else:
print("b")
$JumpLandingHardCrunch.play()
$JumpLandingHardOuch.play()
if not on_floor and phys.is_falling_velocity_terminal() and not $FallingSound.playing:
$FallingSound.play()
$FallingSound.pitch_scale = rand_range(0.8, 1.2)
elif on_floor:
$FallingSound.stop()
func footsteps():
var on_floor = $"../OnFootPhysics/Floor".is_on_floor
var velocity = $"../MovementInput".input_xz
if not on_floor or velocity.length() == 0:
$Footsteps.stop()
return
if $Footsteps/Timer.time_left > 0.0:
return
$Footsteps.pitch_scale = rand_range(0.9, 1.1)
$Footsteps.play()
var is_sprinting = $"../MovementInput".sprinting
if is_sprinting:
$Footsteps/Timer.start(0.3)
else:
$Footsteps/Timer.start(0.5)
func _process(_delta):
if $"..".is_on_foot():
jump()
footsteps()

View File

@ -1,11 +1,13 @@
[gd_scene load_steps=5 format=2]
[gd_scene load_steps=7 format=2]
[ext_resource path="res://effects/player/MovementSounds.gd" type="Script" id=1]
[ext_resource path="res://effects/player/MovementSoundsAnimations.gd" type="Script" id=1]
[ext_resource path="res://assets/FootstepSfx/Steps_water-003.ogg" type="AudioStream" id=2]
[ext_resource path="res://assets/FootstepSfx/Steps_water-016.ogg" type="AudioStream" id=3]
[ext_resource path="res://assets/audio/falling_wind.mp3" type="AudioStream" id=4]
[ext_resource path="res://assets/audio/388019__saturdaysoundguy__celery-snap.ogg" type="AudioStream" id=5]
[ext_resource path="res://assets/audio/404327__pfranzen__male-grunts-and-groans.ogg" type="AudioStream" id=6]
[node name="MovementSounds" type="Node"]
[node name="MovementSoundsAnimations" type="Node"]
script = ExtResource( 1 )
[node name="Footsteps" type="AudioStreamPlayer" parent="."]
@ -21,5 +23,11 @@ stream = ExtResource( 3 )
[node name="JumpLanding" type="AudioStreamPlayer" parent="."]
stream = ExtResource( 3 )
[node name="JumpLandingHardCrunch" type="AudioStreamPlayer" parent="."]
stream = ExtResource( 5 )
[node name="JumpLandingHardOuch" type="AudioStreamPlayer" parent="."]
stream = ExtResource( 6 )
[node name="FallingSound" type="AudioStreamPlayer" parent="."]
stream = ExtResource( 4 )

View File

@ -2,12 +2,16 @@ extends RayCast
var is_on_floor = false
var floor_distance = 0.0
export var min_floor_distance = 0.5
func _process(_delta):
force_raycast_update();
if is_colliding():
is_on_floor = true;
var point = get_collision_point();
floor_distance = to_local(point).length();
if floor_distance < min_floor_distance:
is_on_floor = true
else:
is_on_floor = false
else:
is_on_floor = false;
is_on_floor = false

View File

@ -1,18 +1,10 @@
extends Node
onready var camera = get_parent()
onready var OnFootPhysics = get_node("../../../../../OnFootPhysics")
onready var default_fov = camera.fov
onready var max_fov = default_fov + 20
var min_speed = 0.5
onready var Floor = get_node("../../../../../OnFootPhysics/Floor")
# Commenting out code only addresses falling, but FOV should also change a bit when sprinting.
func _process(_delta):
pass
#if OnFootPhysics.velocity.y >= 0.0:
#
# return
#var terminal_velocity = -OnFootPhysics.get_terminal_falling_velocity()
#var speed = -OnFootPhysics.velocity.y
#var weight = (terminal_velocity - speed) / (terminal_velocity - min_speed)
#camera.fov = lerp(max_fov, default_fov, weight)
if OnFootPhysics.velocity.y >= 0.0 or Floor.is_on_floor:
$FOVAnimation.play("RESET")
return
$FOVAnimation.play("fov")

View File

@ -23,14 +23,17 @@ var velocity_factor: Vector3 = Vector3.ONE
var target_velocity: Vector3 = Vector3.ZERO
var is_jumping: bool = false
var jump_permission: float = 1.0
var is_falling: bool = false
var is_falling_terminally: bool = false
var just_landed: bool = false
var just_landed_terminally: bool = false
func get_terminal_falling_velocity():
return -gravity * .5
return -9
func is_falling_velocity_terminal():
return velocity.y <= get_terminal_falling_velocity()
func process_velocity(delta: float):
# Uses the input from MovementInput to compute and update this node's velocity
# velocity_acceleration controls gradual speedup whereas velocity_friction
@ -52,6 +55,8 @@ func process_velocity(delta: float):
elif is_jumping and $"../MovementInput".jump_intent == 0.0:
jump_permission = 1.0
is_jumping = false
var target_velocity_xz = $"../MovementInput".input_xz
@ -84,6 +89,20 @@ func process_velocity(delta: float):
velocity = util.vec2_xz_to_vec3(velocity_xz, velocity_y) * velocity_factor
func process_falling():
if not $Floor.is_on_floor:
is_falling = true
just_landed = false
just_landed_terminally = false
if is_falling_velocity_terminal():
is_falling_terminally = true
return
just_landed = is_falling
just_landed_terminally = is_falling_terminally
is_falling = false
is_falling_terminally = false
func increase_velocity_factor(by: Vector3):
velocity_factor *= by
@ -94,3 +113,4 @@ func _physics_process(delta):
process_velocity(delta)
velocity = move_and_slide(velocity, Vector3.UP)
process_falling()

View File

@ -7,15 +7,11 @@ onready var OnFootPhysics = get_node("../OnFootPhysics")
var will_fall_hard = false
func _ready():
$HurtScreen.visible = false
$HurtScreen.modulate.a = 0.0
func _process(_delta):
if OnFootPhysics.is_falling_velocity_terminal():
will_fall_hard = true
if will_fall_hard and OnFootPhysics.is_on_floor():
will_fall_hard = false
$HurtScreen.visible = true
$HurtScreen/Timer.start(1)
func _on_Timer_timeout():
$HurtScreen.visible = false
$HurtScreen/HurtScreenOpacityAnimation.play("opacity")

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=19 format=2]
[gd_scene load_steps=28 format=2]
[ext_resource path="res://player/CameraController.gd" type="Script" id=1]
[ext_resource path="res://player/OnFootPhysics.gd" type="Script" id=2]
@ -8,21 +8,146 @@
[ext_resource path="res://player/PlatformMechanics.gd" type="Script" id=6]
[ext_resource path="res://player/ElevatorPhysics.gd" type="Script" id=7]
[ext_resource path="res://effects/player/Flashlight.tscn" type="PackedScene" id=8]
[ext_resource path="res://effects/player/MovementSounds.tscn" type="PackedScene" id=9]
[ext_resource path="res://assets/audio/388019__saturdaysoundguy__celery-snap.ogg" type="AudioStream" id=9]
[ext_resource path="res://player/CloseToFloor.gd" type="Script" id=10]
[ext_resource path="res://player/HighSpeedFOV.gd" type="Script" id=11]
[ext_resource path="res://player/Overlay.gd" type="Script" id=12]
[ext_resource path="res://assets/BloodMush.png" type="Texture" id=13]
[ext_resource path="res://assets/models/walkie_talkie/walkie_talkie.tscn" type="PackedScene" id=14]
[ext_resource path="res://assets/FootstepSfx/Steps_water-016.ogg" type="AudioStream" id=15]
[ext_resource path="res://assets/audio/falling_wind.mp3" type="AudioStream" id=16]
[ext_resource path="res://assets/FootstepSfx/Steps_water-003.ogg" type="AudioStream" id=17]
[ext_resource path="res://assets/audio/404327__pfranzen__male-grunts-and-groans.ogg" type="AudioStream" id=18]
[ext_resource path="res://effects/player/MovementSoundsAnimations.gd" type="Script" id=19]
[sub_resource type="AnimationNodeStateMachine" id=2]
[sub_resource type="Animation" id=8]
length = 0.001
tracks/0/type = "value"
tracks/0/path = NodePath("..:fov")
tracks/0/interp = 0
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0 ),
"transitions": PoolRealArray( 1 ),
"update": 1,
"values": [ 70.0 ]
}
[sub_resource type="AnimationNodeStateMachinePlayback" id=3]
[sub_resource type="Animation" id=9]
resource_name = "fov"
length = 3.0
step = 0.061
tracks/0/type = "value"
tracks/0/path = NodePath("..:fov")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.549, 2.928 ),
"transitions": PoolRealArray( 1, 1, 1 ),
"update": 0,
"values": [ 70.0, 70.0, 110.0 ]
}
[sub_resource type="CylinderShape" id=4]
[sub_resource type="SphereShape" id=5]
[sub_resource type="Animation" id=10]
length = 0.001
tracks/0/type = "bezier"
tracks/0/path = NodePath("../Smoothing/CameraController/Rotation/Camera:translation:x")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"points": PoolRealArray( 0, -0.25, 0, 0.25, 0 ),
"times": PoolRealArray( 0 )
}
tracks/1/type = "bezier"
tracks/1/path = NodePath("../Smoothing/CameraController/Rotation/Camera:translation:y")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"points": PoolRealArray( 0, -0.25, 0, 0.25, 0 ),
"times": PoolRealArray( 0 )
}
tracks/2/type = "bezier"
tracks/2/path = NodePath("../Smoothing/CameraController/Rotation/Camera:translation:z")
tracks/2/interp = 1
tracks/2/loop_wrap = true
tracks/2/imported = false
tracks/2/enabled = true
tracks/2/keys = {
"points": PoolRealArray( 0, -0.25, 0, 0.25, 0 ),
"times": PoolRealArray( 0 )
}
tracks/3/type = "value"
tracks/3/path = NodePath("../Smoothing/CameraController/Rotation/Camera:translation")
tracks/3/interp = 1
tracks/3/loop_wrap = true
tracks/3/imported = false
tracks/3/enabled = true
tracks/3/keys = {
"times": PoolRealArray( 0 ),
"transitions": PoolRealArray( 1 ),
"update": 0,
"values": [ Vector3( 0, 0, 0 ) ]
}
[sub_resource type="Animation" id=11]
resource_name = "jump_landing"
tracks/0/type = "value"
tracks/0/path = NodePath("../Smoothing/CameraController/Rotation/Camera:translation")
tracks/0/interp = 2
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.1, 0.4 ),
"transitions": PoolRealArray( 1, 1, 1 ),
"update": 0,
"values": [ Vector3( 0, 0, 0 ), Vector3( 0, -0.161821, 0 ), Vector3( 0, 0, 0 ) ]
}
[sub_resource type="Animation" id=6]
length = 0.001
tracks/0/type = "value"
tracks/0/path = NodePath(".:modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0 ),
"transitions": PoolRealArray( 1 ),
"update": 0,
"values": [ Color( 1, 1, 1, 0 ) ]
}
[sub_resource type="Animation" id=7]
resource_name = "opacity"
length = 0.46
step = 0.007
tracks/0/type = "value"
tracks/0/path = NodePath(".:modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.112, 0.287, 0.35 ),
"transitions": PoolRealArray( 1, 1, 1, 1 ),
"update": 0,
"values": [ Color( 1, 1, 1, 0 ), Color( 1, 1, 1, 1 ), Color( 1, 1, 1, 1 ), Color( 1, 1, 1, 0 ) ]
}
[node name="Player" type="Spatial"]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.750395, 0 )
script = ExtResource( 3 )
@ -41,14 +166,6 @@ script = ExtResource( 1 )
keep_aspect = 0
current = true
[node name="CameraAnimationFSM" type="AnimationTree" parent="Smoothing/CameraController/Rotation/Camera"]
tree_root = SubResource( 2 )
anim_player = NodePath("../CameraAnimationPlayer")
parameters/playback = SubResource( 3 )
[node name="CameraAnimationPlayer" type="AnimationPlayer" parent="Smoothing/CameraController/Rotation/Camera"]
root_node = NodePath("../CameraAnimationFSM")
[node name="Flashlight" parent="Smoothing/CameraController/Rotation/Camera" instance=ExtResource( 8 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.00211835, 0 )
light_cull_mask = 4294966783
@ -56,6 +173,10 @@ light_cull_mask = 4294966783
[node name="HighSpeedFOV" type="Node" parent="Smoothing/CameraController/Rotation/Camera"]
script = ExtResource( 11 )
[node name="FOVAnimation" type="AnimationPlayer" parent="Smoothing/CameraController/Rotation/Camera/HighSpeedFOV"]
anims/RESET = SubResource( 8 )
anims/fov = SubResource( 9 )
[node name="WalkieTalkie" parent="Smoothing/CameraController/Rotation/Camera" instance=ExtResource( 14 )]
[node name="OnFootPhysics" type="KinematicBody" parent="."]
@ -87,22 +208,50 @@ script = ExtResource( 4 )
[node name="PlatformMechanics" type="Node" parent="."]
script = ExtResource( 6 )
[node name="MovementSounds" parent="." instance=ExtResource( 9 )]
[node name="MovementSoundsAnimations" type="Node" parent="."]
script = ExtResource( 19 )
[node name="Footsteps" type="AudioStreamPlayer" parent="MovementSoundsAnimations"]
stream = ExtResource( 17 )
volume_db = -1.0
[node name="Timer" type="Timer" parent="MovementSoundsAnimations/Footsteps"]
one_shot = true
[node name="Jump" type="AudioStreamPlayer" parent="MovementSoundsAnimations"]
stream = ExtResource( 15 )
[node name="JumpLanding" type="AudioStreamPlayer" parent="MovementSoundsAnimations"]
stream = ExtResource( 15 )
[node name="JumpLandingHardCrunch" type="AudioStreamPlayer" parent="MovementSoundsAnimations"]
stream = ExtResource( 9 )
[node name="JumpLandingHardOuch" type="AudioStreamPlayer" parent="MovementSoundsAnimations"]
stream = ExtResource( 18 )
[node name="FallingSound" type="AudioStreamPlayer" parent="MovementSoundsAnimations"]
stream = ExtResource( 16 )
[node name="CameraAnimation" type="AnimationPlayer" parent="MovementSoundsAnimations"]
anims/RESET = SubResource( 10 )
anims/jump_landing = SubResource( 11 )
[node name="Overlay" type="CanvasLayer" parent="."]
script = ExtResource( 12 )
[node name="HurtScreen" type="TextureRect" parent="Overlay"]
modulate = Color( 1, 1, 1, 0 )
anchor_right = 1.0
anchor_bottom = 1.0
texture = ExtResource( 13 )
stretch_mode = 1
[node name="Timer" type="Timer" parent="Overlay/HurtScreen"]
one_shot = true
[node name="HurtScreenOpacityAnimation" type="AnimationPlayer" parent="Overlay/HurtScreen"]
anims/RESET = SubResource( 6 )
anims/opacity = SubResource( 7 )
[connection signal="area_entered" from="ElevatorPhysics/Area" to="ElevatorPhysics" method="_on_Area_area_entered"]
[connection signal="area_exited" from="ElevatorPhysics/Area" to="ElevatorPhysics" method="_on_Area_area_exited"]
[connection signal="timeout" from="MovementInput/VerticalTimer" to="MovementInput" method="_on_VerticalTimer_timeout"]
[connection signal="timeout" from="MovementInput/HorizontalTimer" to="MovementInput" method="_on_HorizontalTimer_timeout"]
[connection signal="timeout" from="Overlay/HurtScreen/Timer" to="Overlay" method="_on_Timer_timeout"]

View File

@ -19,7 +19,7 @@ mesh = SubResource( 1 )
shape = SubResource( 2 )
[node name="MeshInstance3" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -9.41229, 1.87042 )
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -23.0411, 1.87042 )
mesh = SubResource( 1 )
[node name="StaticBody" type="StaticBody" parent="MeshInstance3"]