upd
This commit is contained in:
56
Code/AI/Enemy.Footsteps.cs
Normal file
56
Code/AI/Enemy.Footsteps.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
public sealed partial class Enemy
|
||||
{
|
||||
public bool DebugFootsteps = false;
|
||||
public bool EnableFootstepSounds = true;
|
||||
private TimeSince _timeSinceStep;
|
||||
|
||||
private void OnFootstepEvent( SceneModel.FootstepEvent e )
|
||||
{
|
||||
if ( EnableFootstepSounds && !(_timeSinceStep < 0.2f) )
|
||||
{
|
||||
_timeSinceStep = 0f;
|
||||
PlayFootstepSound( e.Transform.Position, e.Volume, e.FootId );
|
||||
}
|
||||
}
|
||||
|
||||
[Rpc.Broadcast]
|
||||
public void PlayFootstepSound( Vector3 worldPosition, float volume, int foot )
|
||||
{
|
||||
SceneTrace trace = Scene.Trace;
|
||||
Vector3 from = worldPosition + WorldRotation.Up * 10f;
|
||||
Vector3 to = worldPosition + WorldRotation.Down * 20f;
|
||||
SceneTraceResult sceneTraceResult = trace.Ray( in from, in to ).IgnoreGameObjectHierarchy( GameObject ).Run();
|
||||
if ( !sceneTraceResult.Hit || sceneTraceResult.Surface == null )
|
||||
{
|
||||
if ( DebugFootsteps )
|
||||
{
|
||||
DebugOverlay.Sphere( new Sphere( worldPosition, volume ), Color.Red, 10f, default, overlay: true );
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
SoundEvent soundEvent = ResourceLibrary.Get<SoundEvent>( (foot == 0)
|
||||
? sceneTraceResult.Surface.Sounds.FootLeft
|
||||
: sceneTraceResult.Surface.Sounds.FootRight );
|
||||
if ( soundEvent == null )
|
||||
{
|
||||
if ( DebugFootsteps )
|
||||
{
|
||||
DebugOverlay.Sphere( new Sphere( worldPosition, volume ), Color.Orange, 10f, default, overlay: true );
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
SoundHandle soundHandle = GameObject.PlaySound( soundEvent, 0f );
|
||||
// soundHandle.TargetMixer = FootstepMixer.GetOrDefault();
|
||||
// soundHandle.Volume *= volume * FootstepVolume;
|
||||
if ( DebugFootsteps )
|
||||
{
|
||||
DebugOverlay.Sphere( new Sphere( worldPosition, volume ), default, 10f, default, overlay: true );
|
||||
DebugOverlay.Text( worldPosition, soundEvent.ResourceName ?? "", 14f, TextFlag.LeftTop, default, 10f,
|
||||
default );
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user