Throwing tweaks (#16266)

- Cartridge bounds decreased.
- Throwing pushback scales based on entity mass.
This commit is contained in:
metalgearsloth
2023-05-13 09:54:37 +10:00
committed by GitHub
parent 1f608dd637
commit d86294d547
3 changed files with 21 additions and 7 deletions

View File

@@ -63,7 +63,7 @@ namespace Content.Server.Chemistry.EntitySystems
_physics.SetLinearDamping(physics, 0f); _physics.SetLinearDamping(physics, 0f);
_physics.SetAngularDamping(physics, 0f); _physics.SetAngularDamping(physics, 0f);
_throwing.TryThrow(vapor.Owner, dir, speed, user: user, pushbackRatio: 50f); _throwing.TryThrow(vapor.Owner, dir, speed, user: user, pushbackRatio: ThrowingSystem.PushbackDefault * 10f);
var distance = (target.Position - vaporXform.WorldPosition).Length; var distance = (target.Position - vaporXform.WorldPosition).Length;
var time = (distance / physics.LinearVelocity.Length); var time = (distance / physics.LinearVelocity.Length);

View File

@@ -12,7 +12,9 @@ namespace Content.Shared.Throwing;
public sealed class ThrowingSystem : EntitySystem public sealed class ThrowingSystem : EntitySystem
{ {
public const float ThrowAngularImpulse = 1.5f; public const float ThrowAngularImpulse = 5f;
public const float PushbackDefault = 1f;
/// <summary> /// <summary>
/// The minimum amount of time an entity needs to be thrown before the timer can be run. /// The minimum amount of time an entity needs to be thrown before the timer can be run.
@@ -37,7 +39,7 @@ public sealed class ThrowingSystem : EntitySystem
Vector2 direction, Vector2 direction,
float strength = 1.0f, float strength = 1.0f,
EntityUid? user = null, EntityUid? user = null,
float pushbackRatio = 5.0f) float pushbackRatio = PushbackDefault)
{ {
var physicsQuery = GetEntityQuery<PhysicsComponent>(); var physicsQuery = GetEntityQuery<PhysicsComponent>();
if (!physicsQuery.TryGetComponent(uid, out var physics)) if (!physicsQuery.TryGetComponent(uid, out var physics))
@@ -73,7 +75,7 @@ public sealed class ThrowingSystem : EntitySystem
EntityQuery<TagComponent> tagQuery, EntityQuery<TagComponent> tagQuery,
float strength = 1.0f, float strength = 1.0f,
EntityUid? user = null, EntityUid? user = null,
float pushbackRatio = 5.0f) float pushbackRatio = PushbackDefault)
{ {
if (strength <= 0 || direction == Vector2.Infinity || direction == Vector2.NaN || direction == Vector2.Zero) if (strength <= 0 || direction == Vector2.Infinity || direction == Vector2.NaN || direction == Vector2.Zero)
return; return;
@@ -92,7 +94,7 @@ public sealed class ThrowingSystem : EntitySystem
// Give it a l'il spin. // Give it a l'il spin.
if (!tagQuery.TryGetComponent(uid, out var tag) || !_tagSystem.HasTag(tag, "NoSpinOnThrow")) if (!tagQuery.TryGetComponent(uid, out var tag) || !_tagSystem.HasTag(tag, "NoSpinOnThrow"))
_physics.ApplyAngularImpulse(uid, ThrowAngularImpulse, body: physics); _physics.ApplyAngularImpulse(uid, ThrowAngularImpulse / physics.InvI, body: physics);
else else
transform.LocalRotation = direction.ToWorldAngle() - Math.PI; transform.LocalRotation = direction.ToWorldAngle() - Math.PI;
@@ -124,7 +126,8 @@ public sealed class ThrowingSystem : EntitySystem
// Give thrower an impulse in the other direction // Give thrower an impulse in the other direction
if (user != null && if (user != null &&
pushbackRatio > 0.0f && pushbackRatio != 0.0f &&
physics.Mass > 0f &&
TryComp(user.Value, out PhysicsComponent? userPhysics) && TryComp(user.Value, out PhysicsComponent? userPhysics) &&
_gravity.IsWeightless(user.Value, userPhysics)) _gravity.IsWeightless(user.Value, userPhysics))
{ {
@@ -132,7 +135,7 @@ public sealed class ThrowingSystem : EntitySystem
RaiseLocalEvent(uid, msg); RaiseLocalEvent(uid, msg);
if (!msg.Cancelled) if (!msg.Cancelled)
_physics.ApplyLinearImpulse(user.Value, -impulseVector * pushbackRatio, body: userPhysics); _physics.ApplyLinearImpulse(user.Value, -impulseVector * pushbackRatio * physics.Mass, body: userPhysics);
} }
} }
} }

View File

@@ -6,6 +6,17 @@
- type: Sprite - type: Sprite
drawdepth: Items drawdepth: Items
netsync: false netsync: false
- type: Fixtures
fixtures:
fix1:
shape:
!type:PhysShapeAabb
bounds: "-0.10,-0.05,0.10,0.05"
density: 20
mask:
- ItemMask
restitution: 0.3 # fite me
friction: 0.2
- type: Tag - type: Tag
tags: tags:
- Cartridge - Cartridge