From d341f456de24242950c3dea98259515affb77348 Mon Sep 17 00:00:00 2001 From: Salex08 <33989683+Salex08@users.noreply.github.com> Date: Sat, 5 Nov 2022 04:08:32 +0100 Subject: [PATCH] Shot Projectile cause impulses in Space like they were supposed to (#12264) --- .../Weapons/Ranged/Systems/SharedGunSystem.cs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs index f24c1716e8..569d66496a 100644 --- a/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs +++ b/Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs @@ -5,6 +5,7 @@ using Content.Shared.CombatMode; using Content.Shared.Containers.ItemSlots; using Content.Shared.Damage; using Content.Shared.Examine; +using Content.Shared.Gravity; using Content.Shared.Hands.Components; using Content.Shared.Interaction.Events; using Content.Shared.Popups; @@ -20,6 +21,7 @@ using Robust.Shared.GameStates; using Robust.Shared.Map; using Robust.Shared.Network; using Robust.Shared.Physics.Systems; +using Robust.Shared.Physics.Components; using Robust.Shared.Player; using Robust.Shared.Prototypes; using Robust.Shared.Random; @@ -38,6 +40,7 @@ public abstract partial class SharedGunSystem : EntitySystem [Dependency] protected readonly IRobustRandom Random = default!; [Dependency] protected readonly ISharedAdminLogManager Logs = default!; [Dependency] protected readonly DamageableSystem Damageable = default!; + [Dependency] private readonly SharedGravitySystem Gravity = default!; [Dependency] private readonly ItemSlotsSystem _slots = default!; [Dependency] protected readonly SharedActionsSystem Actions = default!; [Dependency] protected readonly SharedAppearanceSystem Appearance = default!; @@ -285,6 +288,12 @@ public abstract partial class SharedGunSystem : EntitySystem // Shoot confirmed - sounds also played here in case it's invalid (e.g. cartridge already spent). Shoot(gun, ev.Ammo, fromCoordinates, toCoordinates.Value, user); + // Projectiles cause impulses especially important in non gravity environments + if (TryComp(user, out var userPhysics)) + { + if (Gravity.IsWeightless(user, userPhysics)) + CauseImpulse(fromCoordinates, toCoordinates.Value, userPhysics); + } Dirty(gun); } @@ -366,6 +375,16 @@ public abstract partial class SharedGunSystem : EntitySystem CreateEffect(gun, ev, user); } + public void CauseImpulse(EntityCoordinates fromCoordinates, EntityCoordinates toCoordinates, PhysicsComponent userPhysics) + { + var fromMap = fromCoordinates.ToMapPos(EntityManager); + var toMap = toCoordinates.ToMapPos(EntityManager); + var shotDirection = (toMap - fromMap).Normalized; + + const float impulseStrength = 85.0f; //The bullet impulse strength, TODO: In the future we might want to make it more projectile dependent + var impulseVector = shotDirection * impulseStrength; + Physics.ApplyLinearImpulse(userPhysics, -impulseVector); + } protected abstract void CreateEffect(EntityUid uid, MuzzleFlashEvent message, EntityUid? user = null); [Serializable, NetSerializable]