Add falling test

This commit is contained in:
Spencer Killen 2022-11-27 21:06:36 -07:00
parent 40e16bba92
commit c5df54cab5
Signed by: sjkillen
GPG Key ID: F307025B65C860BA
8 changed files with 115 additions and 15 deletions

View File

@ -1,15 +1,11 @@
extends Node extends Node
onready var util = get_node("/root/Util")
var played_jump_sound = false var played_jump_sound = false
func _ready():
"$Footsteps/Timer.time_left = -1.0"
func jump(): func jump():
var on_floor = $"../OnFootPhysics/Floor".is_on_floor var on_floor = $"../OnFootPhysics/Floor".is_on_floor
var jump_intent = $"../MovementInput".jump_intent var jump_intent = $"../MovementInput".jump_intent
var velocity = $"../OnFootPhysics".velocity var falling_fast = $"../OnFootPhysics".is_falling_velocity_terminal()
if jump_intent and not on_floor and not played_jump_sound: if jump_intent and not on_floor and not played_jump_sound:
$Jump.play() $Jump.play()
@ -18,9 +14,11 @@ func jump():
$Jump.stop() $Jump.stop()
$JumpLanding.play() $JumpLanding.play()
played_jump_sound = false played_jump_sound = false
if not on_floor and velocity.z < -10 and not $FallingSound.playing:
if not on_floor and falling_fast and not $FallingSound.playing:
$FallingSound.play() $FallingSound.play()
$FallingSound.pitch_scale = rand_range(0.5, 1.2) $FallingSound.pitch_scale = rand_range(0.5, 1.2)
played_jump_sound = true
elif on_floor: elif on_floor:
$FallingSound.stop() $FallingSound.stop()
@ -29,9 +27,7 @@ func footsteps():
var on_floor = $"../OnFootPhysics/Floor".is_on_floor var on_floor = $"../OnFootPhysics/Floor".is_on_floor
var velocity = $"../MovementInput".input_xz var velocity = $"../MovementInput".input_xz
print($Footsteps/Timer.time_left) if not on_floor or velocity.length() == 0:
if not on_floor or velocity.length() == 0 or not $"..".is_on_foot():
$Footsteps.stop() $Footsteps.stop()
return return
if $Footsteps/Timer.time_left > 0.0: if $Footsteps/Timer.time_left > 0.0:
@ -49,5 +45,6 @@ func footsteps():
func _process(_delta): func _process(_delta):
if $"..".is_on_foot():
jump() jump()
footsteps() footsteps()

View File

@ -1,8 +1,9 @@
[gd_scene load_steps=4 format=2] [gd_scene load_steps=5 format=2]
[ext_resource path="res://effects/player/MovementSounds.gd" type="Script" id=1] [ext_resource path="res://effects/player/MovementSounds.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-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/FootstepSfx/Steps_water-016.ogg" type="AudioStream" id=3]
[ext_resource path="res://assets/audio/falling_wind.mp3" type="AudioStream" id=4]
[node name="MovementSounds" type="Node"] [node name="MovementSounds" type="Node"]
script = ExtResource( 1 ) script = ExtResource( 1 )
@ -21,3 +22,4 @@ stream = ExtResource( 3 )
stream = ExtResource( 3 ) stream = ExtResource( 3 )
[node name="FallingSound" type="AudioStreamPlayer" parent="."] [node name="FallingSound" type="AudioStreamPlayer" parent="."]
stream = ExtResource( 4 )

View File

@ -4,7 +4,6 @@ var elevator_tracker = null
var locked = false var locked = false
func _on_Area_area_entered(area: Node): func _on_Area_area_entered(area: Node):
print(area)
if area.name != "ElevatorGrip" or elevator_tracker != null: if area.name != "ElevatorGrip" or elevator_tracker != null:
return return
elevator_tracker = area.get_parent() elevator_tracker = area.get_parent()

View File

@ -0,0 +1,15 @@
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
func _process(_delta):
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)

View File

@ -15,6 +15,13 @@ var target_velocity: Vector3 = Vector3.ZERO
var is_jumping: bool = false var is_jumping: bool = false
var jump_permission: float = 1.0 var jump_permission: float = 1.0
func get_terminal_falling_velocity():
return -gravity * .5
func is_falling_velocity_terminal():
return velocity.y <= get_terminal_falling_velocity()
func process_velocity(delta: float): func process_velocity(delta: float):
# Uses the input from MovementInput to compute and update this node's velocity # Uses the input from MovementInput to compute and update this node's velocity
# velocity_acceleration controls gradual speedup whereas velocity_friction # velocity_acceleration controls gradual speedup whereas velocity_friction

21
godot/player/Overlay.gd Normal file
View File

@ -0,0 +1,21 @@
extends CanvasLayer
# This is just a proof of concept, feel free to remove.
# This should be triggered by some central damage taking system
onready var OnFootPhysics = get_node("../OnFootPhysics")
var will_fall_hard = false
func _ready():
$HurtScreen.visible = false
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

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=15 format=2] [gd_scene load_steps=18 format=2]
[ext_resource path="res://player/CameraController.gd" type="Script" id=1] [ext_resource path="res://player/CameraController.gd" type="Script" id=1]
[ext_resource path="res://player/OnFootPhysics.gd" type="Script" id=2] [ext_resource path="res://player/OnFootPhysics.gd" type="Script" id=2]
@ -10,6 +10,9 @@
[ext_resource path="res://effects/player/Flashlight.tscn" type="PackedScene" id=8] [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://effects/player/MovementSounds.tscn" type="PackedScene" id=9]
[ext_resource path="res://player/CloseToFloor.gd" type="Script" id=10] [ext_resource path="res://player/CloseToFloor.gd" type="Script" id=10]
[ext_resource path="res://player/FallingFOV.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]
[sub_resource type="AnimationNodeStateMachine" id=2] [sub_resource type="AnimationNodeStateMachine" id=2]
@ -48,6 +51,9 @@ root_node = NodePath("../CameraAnimationFSM")
[node name="Flashlight" parent="Smoothing/CameraController/Rotation/Camera" instance=ExtResource( 8 )] [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 ) transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.00211835, 0 )
[node name="FallingFOV" type="Node" parent="Smoothing/CameraController/Rotation/Camera"]
script = ExtResource( 11 )
[node name="OnFootPhysics" type="KinematicBody" parent="."] [node name="OnFootPhysics" type="KinematicBody" parent="."]
script = ExtResource( 2 ) script = ExtResource( 2 )
@ -79,7 +85,20 @@ script = ExtResource( 6 )
[node name="MovementSounds" parent="." instance=ExtResource( 9 )] [node name="MovementSounds" parent="." instance=ExtResource( 9 )]
[node name="Overlay" type="CanvasLayer" parent="."]
script = ExtResource( 12 )
[node name="HurtScreen" type="TextureRect" parent="Overlay"]
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
[connection signal="area_entered" from="ElevatorPhysics/Area" to="ElevatorPhysics" method="_on_Area_area_entered"] [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="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/VerticalTimer" to="MovementInput" method="_on_VerticalTimer_timeout"]
[connection signal="timeout" from="MovementInput/HorizontalTimer" to="MovementInput" method="_on_HorizontalTimer_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

@ -0,0 +1,40 @@
[gd_scene load_steps=4 format=2]
[ext_resource path="res://player/player.tscn" type="PackedScene" id=1]
[sub_resource type="CubeMesh" id=1]
[sub_resource type="ConcavePolygonShape" id=2]
data = PoolVector3Array( -1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, 1, 1, -1, 1, -1, -1, 1, 1, 1, -1, -1, 1, -1, 1, -1, -1, -1, 1, -1, -1, -1, -1, 1, -1, -1, 1, 1, 1, 1, 1, -1, 1, -1, 1, 1, 1, -1, 1, -1, -1, 1, -1, 1, -1, 1, -1, -1, 1, 1, -1, -1, -1, -1, 1, 1, -1, -1, 1, -1, -1, -1, 1, 1, 1, -1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1, -1, 1, 1, -1, -1, -1, 1, 1, -1, 1, -1, -1, -1, 1, -1, 1, 1, -1, -1, -1, -1, -1 )
[node name="Spatial" type="Spatial"]
[node name="MeshInstance" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -1.17696, 0 )
mesh = SubResource( 1 )
[node name="StaticBody" type="StaticBody" parent="MeshInstance"]
[node name="CollisionShape" type="CollisionShape" parent="MeshInstance/StaticBody"]
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 )
mesh = SubResource( 1 )
[node name="StaticBody" type="StaticBody" parent="MeshInstance3"]
[node name="CollisionShape" type="CollisionShape" parent="MeshInstance3/StaticBody"]
shape = SubResource( 2 )
[node name="MeshInstance2" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -4.05155, -1.69098 )
mesh = SubResource( 1 )
[node name="StaticBody" type="StaticBody" parent="MeshInstance2"]
[node name="CollisionShape" type="CollisionShape" parent="MeshInstance2/StaticBody"]
shape = SubResource( 2 )
[node name="Player" parent="." instance=ExtResource( 1 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.271765, 0 )