Improved footstep detection
This commit is contained in:
parent
07f356a8cc
commit
17a507d07c
@ -1,4 +1,4 @@
|
||||
[gd_scene load_steps=28 format=3 uid="uid://2lcnu3dy54lx"]
|
||||
[gd_scene load_steps=29 format=3 uid="uid://2lcnu3dy54lx"]
|
||||
|
||||
[ext_resource type="Script" path="res://player/Player.gd" id="1_8gebs"]
|
||||
[ext_resource type="PackedScene" uid="uid://c8j7t4yg7anb0" path="res://assets/female/Female.blend" id="2_8nah6"]
|
||||
@ -8,6 +8,7 @@
|
||||
[ext_resource type="PackedScene" uid="uid://cgqbkj8wbcatv" path="res://assets/hair/PonyTail.blend" id="3_umw6q"]
|
||||
[ext_resource type="FontFile" uid="uid://b7mov13kwi8u8" path="res://assets/font/ubuntu_nf_regular.ttf" id="4_76ehj"]
|
||||
[ext_resource type="Skin" uid="uid://bbqyiue1vj37f" path="res://assets/hoodie/Hoodie_Skin.tres" id="4_b1tg1"]
|
||||
[ext_resource type="Resource" uid="uid://1vmnijk8ap6b" path="res://skill/thrust/thrust.tres" id="4_s8cf2"]
|
||||
[ext_resource type="ArrayMesh" uid="uid://dbmluwi2atit" path="res://assets/hoodie/Hoodie_Mesh.res" id="5_mkrgn"]
|
||||
[ext_resource type="PackedScene" uid="uid://6jpnl6c4fdvo" path="res://player/hud/HUDComponent.tscn" id="7_fwgtd"]
|
||||
[ext_resource type="PackedScene" uid="uid://qecdmrg6mbws" path="res://assets/swords/heirloom/Heirloom.blend" id="7_u8433"]
|
||||
@ -35,7 +36,7 @@ height = 1.6
|
||||
collision_layer = 512
|
||||
collision_mask = 769
|
||||
script = ExtResource("1_8gebs")
|
||||
skills = Array[Resource("res://skill/Skill.gd")]([ExtResource("2_x58e1"), ExtResource("3_l76ly"), null, null])
|
||||
skills = Array[Resource("res://skill/Skill.gd")]([ExtResource("2_x58e1"), ExtResource("3_l76ly"), ExtResource("4_s8cf2"), null])
|
||||
|
||||
[node name="Model" type="Node3D" parent="."]
|
||||
|
||||
|
@ -4,47 +4,45 @@ extends Node
|
||||
@export var skeleton: Skeleton3D
|
||||
@export var movement: MovementComponent
|
||||
@export var footsteps: Array[AudioStream]
|
||||
@export var raise_threshold := 0.25
|
||||
@export var step_threshold := 0.15
|
||||
@export var step_threshold := 0.1
|
||||
|
||||
var feet_names := ["LeftFoot", "RightFoot"]
|
||||
var feet := []
|
||||
var feet_audio := []
|
||||
var feet_raised := []
|
||||
var feet_position := []
|
||||
const feet_names := ["LeftFoot", "RightFoot"]
|
||||
|
||||
var feet: Array[Foot] = []
|
||||
|
||||
func _ready():
|
||||
for foot_name in feet_names:
|
||||
var bone_id := skeleton.find_bone(foot_name)
|
||||
var audio := get_node(foot_name)
|
||||
var foot = Foot.new()
|
||||
foot.bone_name = foot_name
|
||||
foot.bone_id = skeleton.find_bone(foot_name)
|
||||
foot.audio = get_node(foot_name)
|
||||
foot.position = skeleton.to_global(skeleton.get_bone_global_pose(foot.bone_id).origin)
|
||||
foot.attachment = BoneAttachment3D.new()
|
||||
foot.attachment.bone_name = foot_name
|
||||
foot.attachment.bone_idx = foot.bone_id
|
||||
foot.audio.reparent(foot.attachment)
|
||||
skeleton.add_child(foot.attachment)
|
||||
feet.append(foot)
|
||||
|
||||
feet.append(bone_id)
|
||||
feet_audio.append(audio)
|
||||
feet_raised.append(false)
|
||||
feet_position.append(Vector3.ZERO)
|
||||
func _process(delta: float):
|
||||
for foot in feet:
|
||||
var old_position := foot.position
|
||||
foot.position = skeleton.to_global(skeleton.get_bone_global_pose(foot.bone_id).origin)
|
||||
foot.velocity = (foot.position - old_position) / delta
|
||||
|
||||
var attachment := BoneAttachment3D.new()
|
||||
attachment.bone_name = foot_name
|
||||
attachment.bone_idx = bone_id
|
||||
audio.reparent(attachment)
|
||||
skeleton.add_child(attachment)
|
||||
if foot.position.y > step_threshold:
|
||||
continue
|
||||
|
||||
func _process(_delta):
|
||||
print()
|
||||
for i in range(feet.size()):
|
||||
feet_position[i] = skeleton.get_bone_global_pose(feet[i]).origin
|
||||
print(feet_position[i].y)
|
||||
if foot.velocity.y > 0:
|
||||
continue
|
||||
|
||||
if feet_position[i].y > raise_threshold:
|
||||
feet_raised[i] = true
|
||||
if foot.velocity.length_squared() < 1.0:
|
||||
continue
|
||||
|
||||
if !movement.body.is_on_floor():
|
||||
return
|
||||
if foot.audio.playing && foot.audio.get_playback_position() < 0.3:
|
||||
continue
|
||||
|
||||
for i in range(feet.size()):
|
||||
if feet_raised[i] && feet_position[i].y < step_threshold:
|
||||
play(feet_audio[i])
|
||||
feet_raised[i] = false
|
||||
play(foot.audio)
|
||||
|
||||
func play(audio_player: AudioStreamPlayer3D):
|
||||
audio_player.stream = footsteps[randi_range(0, footsteps.size()-1)]
|
||||
|
8
client/player/audio/Foot.gd
Normal file
8
client/player/audio/Foot.gd
Normal file
@ -0,0 +1,8 @@
|
||||
class_name Foot
|
||||
|
||||
var bone_name: String
|
||||
var bone_id: int
|
||||
var audio: AudioStreamPlayer3D
|
||||
var position: Vector3
|
||||
var velocity: Vector3
|
||||
var attachment: BoneAttachment3D
|
@ -31,7 +31,6 @@ gdscript/warnings/integer_division=0
|
||||
|
||||
window/size/viewport_width=1920
|
||||
window/size/viewport_height=1080
|
||||
window/size/mode=3
|
||||
window/size/window_width_override=960
|
||||
window/size/window_height_override=540
|
||||
window/stretch/mode="canvas_items"
|
||||
|
6
client/skill/thrust/thrust.gd
Normal file
6
client/skill/thrust/thrust.gd
Normal file
@ -0,0 +1,6 @@
|
||||
extends SkillInstance
|
||||
|
||||
func _ready():
|
||||
play_animation("human/thrust", 1.0, 2.0)
|
||||
await melee_damage(0.5)
|
||||
queue_free()
|
11
client/skill/thrust/thrust.tres
Normal file
11
client/skill/thrust/thrust.tres
Normal file
@ -0,0 +1,11 @@
|
||||
[gd_resource type="Resource" script_class="Skill" load_steps=3 format=3 uid="uid://1vmnijk8ap6b"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://cgycghadwb27h" path="res://skill/thrust/thrust.tscn" id="1_o6s8i"]
|
||||
[ext_resource type="Script" path="res://skill/Skill.gd" id="2_g7hw0"]
|
||||
|
||||
[resource]
|
||||
script = ExtResource("2_g7hw0")
|
||||
id = "thrust"
|
||||
name = "Thrust"
|
||||
cooldown = 0.0
|
||||
scene = ExtResource("1_o6s8i")
|
24
client/skill/thrust/thrust.tscn
Normal file
24
client/skill/thrust/thrust.tscn
Normal file
@ -0,0 +1,24 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://cgycghadwb27h"]
|
||||
|
||||
[ext_resource type="Script" path="res://skill/thrust/thrust.gd" id="1_jtbia"]
|
||||
[ext_resource type="Script" path="res://skill/MeleeArea.gd" id="2_m3c5w"]
|
||||
|
||||
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_6if7n"]
|
||||
radius = 0.7
|
||||
height = 3.0
|
||||
|
||||
[node name="Thrust" type="Node3D"]
|
||||
script = ExtResource("1_jtbia")
|
||||
|
||||
[node name="Area" type="Area3D" parent="."]
|
||||
collision_layer = 0
|
||||
collision_mask = 256
|
||||
monitoring = false
|
||||
monitorable = false
|
||||
script = ExtResource("2_m3c5w")
|
||||
|
||||
[node name="CollisionShape3D" type="CollisionShape3D" parent="Area"]
|
||||
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, -1, 0, 1, -4.37114e-08, 0, 0.7, 1.8)
|
||||
shape = SubResource("CapsuleShape3D_6if7n")
|
||||
|
||||
[connection signal="body_entered" from="Area" to="Area" method="on_body_entered"]
|
Loading…
Reference in New Issue
Block a user