diff --git a/Content.Client/GameObjects/Components/Mobs/SpeciesVisualizer2D.cs b/Content.Client/GameObjects/Components/Mobs/SpeciesVisualizer2D.cs index d49f93f920..1f80e7cbc6 100644 --- a/Content.Client/GameObjects/Components/Mobs/SpeciesVisualizer2D.cs +++ b/Content.Client/GameObjects/Components/Mobs/SpeciesVisualizer2D.cs @@ -1,6 +1,10 @@ -using Content.Shared.GameObjects.Components.Mobs; +using System; +using Content.Shared.GameObjects.Components.Mobs; +using Robust.Client.Animations; using Robust.Client.GameObjects; +using Robust.Client.GameObjects.Components.Animations; using Robust.Client.Interfaces.GameObjects.Components; +using Robust.Shared.Animations; using Robust.Shared.Maths; namespace Content.Client.GameObjects.Components.Mobs @@ -11,19 +15,50 @@ namespace Content.Client.GameObjects.Components.Mobs { base.OnChangeData(component); - var sprite = component.Owner.GetComponent(); if (component.TryGetData(SharedSpeciesComponent.MobVisuals.RotationState, out var state)) { switch (state) { case SharedSpeciesComponent.MobState.Standing: - sprite.Rotation = 0; + SetRotation(component, 0); break; case SharedSpeciesComponent.MobState.Down: - sprite.Rotation = Angle.FromDegrees(90); + SetRotation(component, Angle.FromDegrees(90)); break; } } } + + public void SetRotation(AppearanceComponent component, Angle rotation) + { + var sprite = component.Owner.GetComponent(); + + if (!sprite.Owner.TryGetComponent(out AnimationPlayerComponent animation)) + { + sprite.Rotation = rotation; + return; + } + + animation.Stop("rotate"); + + animation.Play(new Animation + { + Length = TimeSpan.FromSeconds(0.125), + AnimationTracks = + { + new AnimationTrackComponentProperty + { + ComponentType = typeof(ISpriteComponent), + Property = nameof(ISpriteComponent.Rotation), + InterpolationMode = AnimationInterpolationMode.Linear, + KeyFrames = + { + new AnimationTrackProperty.KeyFrame(sprite.Rotation, 0), + new AnimationTrackProperty.KeyFrame(rotation, 0.125f) + } + } + } + }, "rotate"); + } } } diff --git a/Resources/Prototypes/Entities/Mobs/human.yml b/Resources/Prototypes/Entities/Mobs/human.yml index fdae22bac7..0d251b7c2b 100644 --- a/Resources/Prototypes/Entities/Mobs/human.yml +++ b/Resources/Prototypes/Entities/Mobs/human.yml @@ -128,6 +128,7 @@ - type: HumanoidAppearance - type: HumanInventoryController - type: Stunnable + - type: AnimationPlayer - type: entity save: false