NPCs/Stimuli/FootstepStimulus.cs
namespace Opium.AI;
/// <summary>
/// We've heard a footstep
/// </summary>
public class FootstepStimulus : Stimulus
{
public float Volume;
public FootstepStimulus( Vector3 position, float volume = 1 ) : base( position )
{
Volume = volume;
}
public static FootstepStimulus From( SceneModel.FootstepEvent e )
{
return new FootstepStimulus( e.Transform.Position, e.Volume );
}
public static FootstepStimulus From( Agent agent, float volume = 1f )
{
return new FootstepStimulus( agent.Transform.Position, volume )
{
Actor = agent
};
}
public override bool ShouldReact( Actor actor )
{
// Are we reacting to our own footsteps?
if ( actor == Actor ) return false;
if ( actor is Agent agent && agent.NoReactionToSound ) return false;
float distance = Position.Distance( actor.Transform.Position );
distance *= Volume;
float maxRange = 256;
return distance < maxRange;
}
}