Shuttle impact sounds (#11099)
This commit is contained in:
58
Content.Server/Shuttles/Systems/ShuttleSystem.Impact.cs
Normal file
58
Content.Server/Shuttles/Systems/ShuttleSystem.Impact.cs
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
using Content.Server.Shuttles.Components;
|
||||||
|
using Robust.Shared.Audio;
|
||||||
|
using Robust.Shared.Map;
|
||||||
|
using Robust.Shared.Physics.Dynamics;
|
||||||
|
using Robust.Shared.Physics.Events;
|
||||||
|
using Robust.Shared.Player;
|
||||||
|
|
||||||
|
namespace Content.Server.Shuttles.Systems;
|
||||||
|
|
||||||
|
public sealed partial class ShuttleSystem
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Minimum velocity difference between 2 bodies for a shuttle "impact" to occur.
|
||||||
|
/// </summary>
|
||||||
|
private const int MinimumImpactVelocity = 10;
|
||||||
|
|
||||||
|
private readonly SoundCollectionSpecifier _shuttleImpactSound = new("ShuttleImpactSound");
|
||||||
|
|
||||||
|
private void InitializeImpact()
|
||||||
|
{
|
||||||
|
SubscribeLocalEvent<ShuttleComponent, StartCollideEvent>(OnShuttleCollide);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnShuttleCollide(EntityUid uid, ShuttleComponent component, ref StartCollideEvent args)
|
||||||
|
{
|
||||||
|
var ourBody = args.OurFixture.Body;
|
||||||
|
var otherBody = args.OtherFixture.Body;
|
||||||
|
|
||||||
|
if (!HasComp<ShuttleComponent>(otherBody.Owner))
|
||||||
|
return;
|
||||||
|
|
||||||
|
// TODO: Would also be nice to have a continuous sound for scraping.
|
||||||
|
var ourXform = Transform(ourBody.Owner);
|
||||||
|
|
||||||
|
if (ourXform.MapUid == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var otherXform = Transform(otherBody.Owner);
|
||||||
|
|
||||||
|
var ourPoint = ourXform.InvWorldMatrix.Transform(args.WorldPoint);
|
||||||
|
var otherPoint = otherXform.InvWorldMatrix.Transform(args.WorldPoint);
|
||||||
|
|
||||||
|
var ourVelocity = _physics.GetLinearVelocity(ourBody.Owner, ourPoint, ourBody, ourXform);
|
||||||
|
var otherVelocity = _physics.GetLinearVelocity(otherBody.Owner, otherPoint, otherBody, otherXform);
|
||||||
|
var jungleDiff = (ourVelocity - otherVelocity).Length;
|
||||||
|
|
||||||
|
if (jungleDiff < MinimumImpactVelocity)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var coordinates = new EntityCoordinates(ourXform.MapUid.Value, args.WorldPoint);
|
||||||
|
var volume = MathF.Min(10f, 1f * MathF.Pow(jungleDiff, 0.5f) - 5f);
|
||||||
|
var audioParams = AudioParams.Default.WithVariation(0.05f).WithVolume(volume);
|
||||||
|
|
||||||
|
_audio.Play(_shuttleImpactSound, Filter.Pvs(coordinates, rangeMultiplier: 4f, entityMan: EntityManager), coordinates, audioParams);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@ namespace Content.Server.Shuttles.Systems
|
|||||||
{
|
{
|
||||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||||
[Dependency] private readonly FixtureSystem _fixtures = default!;
|
[Dependency] private readonly FixtureSystem _fixtures = default!;
|
||||||
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||||
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
||||||
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
|
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
|
||||||
|
|
||||||
@@ -36,6 +37,7 @@ namespace Content.Server.Shuttles.Systems
|
|||||||
InitializeEscape();
|
InitializeEscape();
|
||||||
InitializeFTL();
|
InitializeFTL();
|
||||||
InitializeIFF();
|
InitializeIFF();
|
||||||
|
InitializeImpact();
|
||||||
|
|
||||||
SubscribeLocalEvent<ShuttleComponent, ComponentAdd>(OnShuttleAdd);
|
SubscribeLocalEvent<ShuttleComponent, ComponentAdd>(OnShuttleAdd);
|
||||||
SubscribeLocalEvent<ShuttleComponent, ComponentStartup>(OnShuttleStartup);
|
SubscribeLocalEvent<ShuttleComponent, ComponentStartup>(OnShuttleStartup);
|
||||||
|
|||||||
BIN
Resources/Audio/Effects/Shuttle/shuttle_impact1.ogg
Normal file
BIN
Resources/Audio/Effects/Shuttle/shuttle_impact1.ogg
Normal file
Binary file not shown.
BIN
Resources/Audio/Effects/Shuttle/shuttle_impact2.ogg
Normal file
BIN
Resources/Audio/Effects/Shuttle/shuttle_impact2.ogg
Normal file
Binary file not shown.
BIN
Resources/Audio/Effects/Shuttle/shuttle_impact3.ogg
Normal file
BIN
Resources/Audio/Effects/Shuttle/shuttle_impact3.ogg
Normal file
Binary file not shown.
6
Resources/Prototypes/SoundCollections/shuttle.yml
Normal file
6
Resources/Prototypes/SoundCollections/shuttle.yml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
- type: soundCollection
|
||||||
|
id: ShuttleImpactSound
|
||||||
|
files:
|
||||||
|
- "/Audio/Effects/Shuttle/shuttle_impact1.ogg"
|
||||||
|
- "/Audio/Effects/Shuttle/shuttle_impact2.ogg"
|
||||||
|
- "/Audio/Effects/Shuttle/shuttle_impact3.ogg"
|
||||||
Reference in New Issue
Block a user