Add footstep sound effect and animation
Sound is linked to Animation so it always plays when the camera nods down
This commit is contained in:
parent
8403eb4716
commit
1cf65caed8
10
Characters/Player/Footsteps.gd
Normal file
10
Characters/Player/Footsteps.gd
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
extends Spatial
|
||||||
|
|
||||||
|
|
||||||
|
onready var steps = [
|
||||||
|
get_node("Footstep1")
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
func play_footstep():
|
||||||
|
steps[0].play()
|
@ -3,6 +3,7 @@ extends KinematicBody
|
|||||||
# export variables
|
# export variables
|
||||||
export(NodePath) var body_nodepath
|
export(NodePath) var body_nodepath
|
||||||
export(NodePath) var lookingAt_nodepath
|
export(NodePath) var lookingAt_nodepath
|
||||||
|
export(NodePath) var animation_nodepath
|
||||||
export(NodePath) var ui_interact_nodepath
|
export(NodePath) var ui_interact_nodepath
|
||||||
export(int) var keycard_lvl
|
export(int) var keycard_lvl
|
||||||
export(Array) var key_chain
|
export(Array) var key_chain
|
||||||
@ -21,6 +22,7 @@ const INTERACT_DISTANCE = 4
|
|||||||
var _body: Spatial
|
var _body: Spatial
|
||||||
var _camera: Camera
|
var _camera: Camera
|
||||||
var _lookCast: RayCast
|
var _lookCast: RayCast
|
||||||
|
var _animation: AnimationPlayer
|
||||||
var _dir = Vector3();
|
var _dir = Vector3();
|
||||||
var _vel = Vector3();
|
var _vel = Vector3();
|
||||||
var _is_sprinting;
|
var _is_sprinting;
|
||||||
@ -30,17 +32,21 @@ var _inventory: Control
|
|||||||
|
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
|
# Assign child node variables
|
||||||
_body = get_node(body_nodepath) as Spatial # = $Body
|
_body = get_node(body_nodepath) as Spatial # = $Body
|
||||||
assert(null != _body)
|
assert(null != _body)
|
||||||
|
|
||||||
_camera = $Body/Camera
|
_camera = $Body/Camera
|
||||||
assert(null != _camera)
|
assert(null != _camera)
|
||||||
|
|
||||||
|
_animation = get_node(animation_nodepath) as AnimationPlayer
|
||||||
|
assert(null != _animation)
|
||||||
|
|
||||||
|
# Setup mouse look
|
||||||
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
Input.set_mouse_mode(Input.MOUSE_MODE_CAPTURED)
|
||||||
_lookCast = get_node(lookingAt_nodepath) as RayCast
|
_lookCast = get_node(lookingAt_nodepath) as RayCast
|
||||||
_lookCast.cast_to = Vector3(0, 0, INTERACT_DISTANCE)
|
_lookCast.cast_to = Vector3(0, 0, INTERACT_DISTANCE)
|
||||||
|
|
||||||
# TODO: move to declaration:
|
|
||||||
ui_interact_nodepath = get_node("HUD").get_node("PressInteract").get_path()
|
|
||||||
|
|
||||||
_inventory = get_node("HUD")
|
_inventory = get_node("HUD")
|
||||||
|
|
||||||
|
|
||||||
@ -50,6 +56,7 @@ func _physics_process(delta):
|
|||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
check_interact()
|
check_interact()
|
||||||
|
process_animations()
|
||||||
|
|
||||||
func process_input():
|
func process_input():
|
||||||
# Walking
|
# Walking
|
||||||
@ -100,6 +107,11 @@ func process_movement(delta):
|
|||||||
_vel.z = hvel.z
|
_vel.z = hvel.z
|
||||||
_vel = move_and_slide(_vel, Vector3(0, 1, 0), 0.05, 4, deg2rad(MAX_SLOPE_ANGLE))
|
_vel = move_and_slide(_vel, Vector3(0, 1, 0), 0.05, 4, deg2rad(MAX_SLOPE_ANGLE))
|
||||||
|
|
||||||
|
|
||||||
|
func process_animations():
|
||||||
|
_animation.playback_speed = _vel.length() / MOVE_SPEED
|
||||||
|
|
||||||
|
|
||||||
func check_interact():
|
func check_interact():
|
||||||
if _lookCast.is_colliding():
|
if _lookCast.is_colliding():
|
||||||
var collider = _lookCast.get_collider()
|
var collider = _lookCast.get_collider()
|
||||||
@ -130,6 +142,7 @@ func check_interact():
|
|||||||
#stop showing interact tooltip
|
#stop showing interact tooltip
|
||||||
get_node(ui_interact_nodepath).hide()
|
get_node(ui_interact_nodepath).hide()
|
||||||
|
|
||||||
|
|
||||||
func _input(event):
|
func _input(event):
|
||||||
# capture mouse movement
|
# capture mouse movement
|
||||||
if event is InputEventMouseMotion:
|
if event is InputEventMouseMotion:
|
||||||
@ -140,4 +153,3 @@ func _input(event):
|
|||||||
camera_rot.x = clamp(camera_rot.x, -70, 70)
|
camera_rot.x = clamp(camera_rot.x, -70, 70)
|
||||||
_body.rotation_degrees = camera_rot
|
_body.rotation_degrees = camera_rot
|
||||||
# interact with object player is looking at
|
# interact with object player is looking at
|
||||||
|
|
||||||
|
@ -1,10 +1,50 @@
|
|||||||
[gd_scene load_steps=4 format=2]
|
[gd_scene load_steps=8 format=2]
|
||||||
|
|
||||||
[ext_resource path="res://Characters/Player/Player.gd" type="Script" id=1]
|
[ext_resource path="res://Characters/Player/Player.gd" type="Script" id=1]
|
||||||
[ext_resource path="res://Characters/Player/UI/UI.tscn" type="PackedScene" id=2]
|
[ext_resource path="res://Characters/Player/Footsteps.gd" type="Script" id=2]
|
||||||
|
[ext_resource path="res://Resources/Audio/Step.wav" type="AudioStream" id=3]
|
||||||
|
[ext_resource path="res://Characters/Player/UI/UI.tscn" type="PackedScene" id=4]
|
||||||
|
|
||||||
[sub_resource type="CylinderShape" id=1]
|
[sub_resource type="CylinderShape" id=1]
|
||||||
|
|
||||||
|
[sub_resource type="Animation" id=2]
|
||||||
|
resource_name = "Walk"
|
||||||
|
length = 0.8
|
||||||
|
loop = true
|
||||||
|
tracks/0/type = "value"
|
||||||
|
tracks/0/path = NodePath("Body/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.2, 0.4, 0.6 ),
|
||||||
|
"transitions": PoolRealArray( 1, 1, 1, 1 ),
|
||||||
|
"update": 0,
|
||||||
|
"values": [ Vector3( 0, 1.8, 0 ), Vector3( -0.1, 1.9, 0 ), Vector3( 0, 1.8, 0 ), Vector3( 0.1, 1.9, 0 ) ]
|
||||||
|
}
|
||||||
|
tracks/1/type = "method"
|
||||||
|
tracks/1/path = NodePath("Footsteps")
|
||||||
|
tracks/1/interp = 1
|
||||||
|
tracks/1/loop_wrap = true
|
||||||
|
tracks/1/imported = false
|
||||||
|
tracks/1/enabled = true
|
||||||
|
tracks/1/keys = {
|
||||||
|
"times": PoolRealArray( 0.3, 0.7 ),
|
||||||
|
"transitions": PoolRealArray( 1, 1 ),
|
||||||
|
"values": [ {
|
||||||
|
"args": [ ],
|
||||||
|
"method": "play_footstep"
|
||||||
|
}, {
|
||||||
|
"args": [ ],
|
||||||
|
"method": "play_footstep"
|
||||||
|
} ]
|
||||||
|
}
|
||||||
|
|
||||||
|
[sub_resource type="AudioStreamRandomPitch" id=3]
|
||||||
|
audio_stream = ExtResource( 3 )
|
||||||
|
random_pitch = 1.3
|
||||||
|
|
||||||
[node name="Player" type="KinematicBody" groups=[
|
[node name="Player" type="KinematicBody" groups=[
|
||||||
"Player",
|
"Player",
|
||||||
]]
|
]]
|
||||||
@ -13,20 +53,40 @@ collision_mask = 5
|
|||||||
script = ExtResource( 1 )
|
script = ExtResource( 1 )
|
||||||
body_nodepath = NodePath("Body")
|
body_nodepath = NodePath("Body")
|
||||||
lookingAt_nodepath = NodePath("Body/Camera/LookingAt")
|
lookingAt_nodepath = NodePath("Body/Camera/LookingAt")
|
||||||
|
animation_nodepath = NodePath("AnimationPlayer")
|
||||||
|
ui_interact_nodepath = NodePath("HUD")
|
||||||
|
|
||||||
[node name="Body" type="Spatial" parent="."]
|
[node name="Body" type="Spatial" parent="."]
|
||||||
|
|
||||||
[node name="Camera" type="Camera" parent="Body"]
|
[node name="Camera" type="Camera" parent="Body"]
|
||||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0 )
|
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0.0625, 1.85, 0 )
|
||||||
current = true
|
current = true
|
||||||
|
|
||||||
[node name="LookingAt" type="RayCast" parent="Body/Camera"]
|
[node name="LookingAt" type="RayCast" parent="Body/Camera"]
|
||||||
transform = Transform( -1, 0, -8.74228e-008, 0, 1, 0, 8.74228e-008, 0, -1, 0, 0, 0 )
|
transform = Transform( -1, 0, -8.74228e-08, 0, 1, 0, 8.74228e-08, 0, -1, 0, 0, 0 )
|
||||||
enabled = true
|
enabled = true
|
||||||
cast_to = Vector3( 0, 0, 2 )
|
cast_to = Vector3( 0, 0, 2 )
|
||||||
|
|
||||||
|
[node name="Listener" type="Listener" parent="Body/Camera"]
|
||||||
|
current = true
|
||||||
|
|
||||||
[node name="Collider" type="CollisionShape" parent="."]
|
[node name="Collider" type="CollisionShape" parent="."]
|
||||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0 )
|
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0 )
|
||||||
shape = SubResource( 1 )
|
shape = SubResource( 1 )
|
||||||
|
|
||||||
[node name="HUD" parent="." instance=ExtResource( 2 )]
|
[node name="AnimationPlayer" type="AnimationPlayer" parent="."]
|
||||||
|
autoplay = "Walk"
|
||||||
|
anims/Walk = SubResource( 2 )
|
||||||
|
|
||||||
|
[node name="Footsteps" type="Spatial" parent="."]
|
||||||
|
script = ExtResource( 2 )
|
||||||
|
|
||||||
|
[node name="Footstep1" type="AudioStreamPlayer3D" parent="Footsteps"]
|
||||||
|
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1 )
|
||||||
|
stream = SubResource( 3 )
|
||||||
|
unit_db = -25.0
|
||||||
|
pitch_scale = 1.5
|
||||||
|
|
||||||
|
[node name="HUD" parent="." instance=ExtResource( 4 )]
|
||||||
|
|
||||||
|
[editable path="HUD"]
|
||||||
|
BIN
Resources/Audio/Step.wav
Normal file
BIN
Resources/Audio/Step.wav
Normal file
Binary file not shown.
21
Resources/Audio/Step.wav.import
Normal file
21
Resources/Audio/Step.wav.import
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
[remap]
|
||||||
|
|
||||||
|
importer="wav"
|
||||||
|
type="AudioStreamSample"
|
||||||
|
path="res://.import/Step.wav-7d0ddf0513d871cbc1043ef07a7bc4cb.sample"
|
||||||
|
|
||||||
|
[deps]
|
||||||
|
|
||||||
|
source_file="res://Resources/Audio/Step.wav"
|
||||||
|
dest_files=[ "res://.import/Step.wav-7d0ddf0513d871cbc1043ef07a7bc4cb.sample" ]
|
||||||
|
|
||||||
|
[params]
|
||||||
|
|
||||||
|
force/8_bit=false
|
||||||
|
force/mono=false
|
||||||
|
force/max_rate=false
|
||||||
|
force/max_rate_hz=44100
|
||||||
|
edit/trim=true
|
||||||
|
edit/normalize=true
|
||||||
|
edit/loop=false
|
||||||
|
compress/mode=0
|
Loading…
x
Reference in New Issue
Block a user