Vehicle camera lurching fix + drawdepth fix (#7783)
This commit is contained in:
@@ -1,32 +1,34 @@
|
||||
using Robust.Client.GameObjects;
|
||||
using Content.Shared.Vehicle;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.GameObjects;
|
||||
|
||||
namespace Content.Client.Vehicle
|
||||
{
|
||||
/// <summary>
|
||||
/// Controls client-side visuals for
|
||||
/// vehicles
|
||||
/// </summary>
|
||||
public sealed class VehicleSystem : VisualizerSystem<VehicleVisualsComponent>
|
||||
public sealed class VehicleSystem : EntitySystem
|
||||
{
|
||||
protected override void OnAppearanceChange(EntityUid uid, VehicleVisualsComponent component, ref AppearanceChangeEvent args)
|
||||
[Dependency] private readonly IEyeManager _eyeManager = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
/// First check is for the sprite itself
|
||||
if (TryComp(uid, out SpriteComponent? sprite)
|
||||
&& args.Component.TryGetData(VehicleVisuals.DrawDepth, out int drawDepth) && sprite != null)
|
||||
{
|
||||
sprite.DrawDepth = drawDepth;
|
||||
}
|
||||
/// Set vehicle layer to animated or not (i.e. are the wheels turning or not)
|
||||
if (args.Component.TryGetData(VehicleVisuals.AutoAnimate, out bool autoAnimate))
|
||||
{
|
||||
sprite?.LayerSetAutoAnimated(VehicleVisualLayers.AutoAnimate, autoAnimate);
|
||||
}
|
||||
base.Initialize();
|
||||
SubscribeNetworkEvent<BuckledToVehicleEvent>(OnBuckle);
|
||||
}
|
||||
|
||||
private void OnBuckle(BuckledToVehicleEvent args)
|
||||
{
|
||||
// Use the vehicle's eye if we get buckled
|
||||
if (args.Buckling)
|
||||
{
|
||||
if (!TryComp<EyeComponent>(args.Vehicle, out var vehicleEye) || vehicleEye.Eye == null)
|
||||
return;
|
||||
_eyeManager.CurrentEye = vehicleEye.Eye;
|
||||
return;
|
||||
}
|
||||
// Reset if we get unbuckled.
|
||||
if (!TryComp<EyeComponent>(args.Rider, out var component) || component.Eye == null)
|
||||
return; // This probably will never happen but in this strange new world we probably want to maintain our old vision
|
||||
_eyeManager.CurrentEye = component.Eye;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
public enum VehicleVisualLayers : byte
|
||||
{
|
||||
/// Layer for the vehicle's wheels
|
||||
AutoAnimate,
|
||||
}
|
||||
|
||||
32
Content.Client/Vehicle/VehicleVisualsSystem.cs
Normal file
32
Content.Client/Vehicle/VehicleVisualsSystem.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Robust.Client.GameObjects;
|
||||
using Content.Shared.Vehicle;
|
||||
|
||||
namespace Content.Client.Vehicle
|
||||
{
|
||||
/// <summary>
|
||||
/// Controls client-side visuals for
|
||||
/// vehicles
|
||||
/// </summary>
|
||||
public sealed class VehicleVisualsSystem : VisualizerSystem<VehicleVisualsComponent>
|
||||
{
|
||||
protected override void OnAppearanceChange(EntityUid uid, VehicleVisualsComponent component, ref AppearanceChangeEvent args)
|
||||
{
|
||||
/// First check is for the sprite itself
|
||||
if (TryComp(uid, out SpriteComponent? sprite)
|
||||
&& args.Component.TryGetData(VehicleVisuals.DrawDepth, out int drawDepth) && sprite != null)
|
||||
{
|
||||
sprite.DrawDepth = drawDepth;
|
||||
}
|
||||
/// Set vehicle layer to animated or not (i.e. are the wheels turning or not)
|
||||
if (args.Component.TryGetData(VehicleVisuals.AutoAnimate, out bool autoAnimate))
|
||||
{
|
||||
sprite?.LayerSetAutoAnimated(VehicleVisualLayers.AutoAnimate, autoAnimate);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public enum VehicleVisualLayers : byte
|
||||
{
|
||||
/// Layer for the vehicle's wheels
|
||||
AutoAnimate,
|
||||
}
|
||||
@@ -10,8 +10,10 @@ using Content.Server.Light.Components;
|
||||
using Content.Server.Buckle.Components;
|
||||
using Content.Server.Hands.Systems;
|
||||
using Content.Shared.Tag;
|
||||
using Content.Server.Mind.Components;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Server.Vehicle
|
||||
{
|
||||
@@ -24,7 +26,6 @@ namespace Content.Server.Vehicle
|
||||
[Dependency] private readonly TagSystem _tagSystem = default!;
|
||||
[Dependency] private readonly ItemSlotsSystem _itemSlotsSystem = default!;
|
||||
[Dependency] private readonly RiderSystem _riderSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
@@ -68,6 +69,10 @@ namespace Content.Server.Vehicle
|
||||
/// </summary>
|
||||
private void OnBuckleChange(EntityUid uid, VehicleComponent component, BuckleChangeEvent args)
|
||||
{
|
||||
// Send an event that our vehicle buckle changed
|
||||
if (TryComp<MindComponent>(args.BuckledEntity, out var mind) && mind.Mind != null && mind.Mind.TryGetSession(out var session))
|
||||
RaiseNetworkEvent(new BuckledToVehicleEvent(uid, args.BuckledEntity, args.Buckling), Filter.SinglePlayer(session));
|
||||
|
||||
if (args.Buckling)
|
||||
{
|
||||
// Add a virtual item to rider's hand, unbuckle if we can't.
|
||||
@@ -200,16 +205,16 @@ namespace Content.Server.Vehicle
|
||||
{
|
||||
return xform.LocalRotation.Degrees switch
|
||||
{
|
||||
< 135f => 10,
|
||||
< 135f => 5,
|
||||
<= 225f => 2,
|
||||
_ => 10
|
||||
_ => 5
|
||||
};
|
||||
}
|
||||
return xform.LocalRotation.Degrees switch
|
||||
{
|
||||
< 45f => 10,
|
||||
< 45f => 5,
|
||||
<= 315f => 2,
|
||||
_ => 10
|
||||
_ => 5
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -48,4 +48,26 @@ namespace Content.Shared.Vehicle
|
||||
/// Raised when someone honks a vehicle horn
|
||||
/// </summary>
|
||||
public sealed class HonkActionEvent : InstantActionEvent { }
|
||||
|
||||
/// <summary>
|
||||
/// Raised on the rider when someone is buckled to a vehicle.
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class BuckledToVehicleEvent : EntityEventArgs
|
||||
{
|
||||
public EntityUid Vehicle;
|
||||
|
||||
public EntityUid Rider;
|
||||
|
||||
/// <summary>
|
||||
/// Whether they were buckled or unbuckled
|
||||
/// </summary>
|
||||
public bool Buckling;
|
||||
public BuckledToVehicleEvent(EntityUid vehicle, EntityUid rider, bool buckling)
|
||||
{
|
||||
Vehicle = vehicle;
|
||||
Rider = rider;
|
||||
Buckling = buckling;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
- type: MovementSpeedModifier
|
||||
baseWalkSpeed : 7
|
||||
baseSprintSpeed : 7
|
||||
- type: Eye
|
||||
- type: Tag
|
||||
- type: Pullable
|
||||
- type: Physics
|
||||
|
||||
Reference in New Issue
Block a user