This commit is contained in:
Oscar 2024-10-30 10:54:15 +03:00
parent f6ac6dd67c
commit 05de6cd4b5
3 changed files with 65 additions and 5 deletions

@ -57,9 +57,9 @@
},
{
"__type": "AnimationHelper",
"__guid": "536068a6-fe5d-4f45-af74-9522ebf7e663",
"__guid": "c5781f89-5808-4b4f-8971-343abe63b1da",
"BodyWeight": 1,
"EyesWeight": 0,
"EyesWeight": 1,
"HeadWeight": 1,
"LookAtEnabled": true,
"Target": {
@ -70,9 +70,9 @@
}
},
{
"__type": "PlayerDresser",
"__guid": "9e0e0634-d503-4286-ace6-a8b6f1303e94",
"BodyRenderer": {
"__type": "FootSteps",
"__guid": "f6ee40f5-5541-4a85-bc06-259b451d0891",
"Source": {
"_type": "component",
"component_id": "4fd8c36d-180b-41af-8439-6b975ca1c7b3",
"go": "b99ceffc-a173-4a6e-a239-6d3c1612c09f",

59
Code/FootSteps.cs Normal file

@ -0,0 +1,59 @@
using Sandbox;
using static Sandbox.VertexLayout;
public sealed class FootSteps : Component
{
[Property] SkinnedModelRenderer Source { get; set; }
protected override void OnEnabled()
{
if ( Source is null )
return;
Source.OnFootstepEvent += OnEvent;
}
protected override void OnDisabled()
{
if ( Source is null )
return;
Source.OnFootstepEvent -= OnEvent;
}
TimeSince timeSinceStep;
void OnEvent( SceneModel.FootstepEvent e )
{
if (IsProxy)
return;
if ( timeSinceStep < 0.2f )
return;
var tr = Scene.Trace
.Ray( e.Transform.Position + Vector3.Up * 20, e.Transform.Position + Vector3.Up * -20 )
.Run();
if ( !tr.Hit )
return;
if ( tr.Surface is null )
return;
timeSinceStep = 0;
var sound = e.FootId == 0 ? tr.Surface.Sounds.FootLeft : tr.Surface.Sounds.FootRight;
if ( sound is null ) return;
var position = tr.HitPosition + tr.Normal * 5;
BroadcastFootstep(sound, position, e.Volume);
}
[Broadcast]
void BroadcastFootstep(string sound, Vector3 position, float volume)
{
var handle = Sound.Play(sound, position);
handle.Volume *= volume;
}
}

@ -2,4 +2,5 @@
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=C_003A_005CUsers_005Chamit_005Fba31xcg_005CDocuments_005Cs_0026box_0020projects_005Ckakozuzo_005F2_005CLibraries_005Cfish_002Escc_005Ccode_005CAssembly_002Ecs/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/AddReferences/RecentPaths/=C_003A_005CUsers_005Chamit_005Fba31xcg_005CDocuments_005Cs_0026box_0020projects_005Ckakozuzo_005F2_005CLibraries_005Cfish_002Escc_005Cscc_002Esbproj/@EntryIndexedValue">True</s:Boolean>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ANetworking_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F81ecae4f6275493893a36d9c54b5776d233200_003F73_003F8bf7d187_003FNetworking_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ASkinnedModelRenderer_002EParameters_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003FAppData_003FRoaming_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FSourcesCache_003Fed128fe9d254c953a46da1ac97997e29107b59c8f1369a7bff15f3d718978_003FSkinnedModelRenderer_002EParameters_002Ecs/@EntryIndexedValue">ForceIncluded</s:String>
</wpf:ResourceDictionary>