SubscribeLocalEvent<LerpingEyeComponent, LocalPlayerDetachedEvent>(OnDetached);
UpdatesAfter.Add(typeof(TransformSystem));
- UpdatesAfter.Add(typeof(PhysicsSystem));
+ UpdatesAfter.Add(typeof(Robust.Client.Physics.PhysicsSystem));
UpdatesBefore.Add(typeof(SharedEyeSystem));
UpdatesOutsidePrediction = true;
}
using System.Numerics;
using Content.Client.Physics.Controllers;
+using Content.Client.PhysicsSystem.Controllers;
using Content.Shared.Movement.Components;
using Content.Shared.NPC;
using Content.Shared.NPC.Events;
using Content.Shared.Movement.Components;
using Content.Shared.Movement.Pulling.Components;
using Content.Shared.Movement.Systems;
-using Robust.Client.GameObjects;
using Robust.Client.Physics;
using Robust.Client.Player;
using Robust.Shared.Configuration;
-using Robust.Shared.Physics.Components;
using Robust.Shared.Player;
using Robust.Shared.Timing;
-namespace Content.Client.Physics.Controllers;
+namespace Content.Client.PhysicsSystem.Controllers;
public sealed class MoverController : SharedMoverController
{
private void HandleClientsideMovement(EntityUid player, float frameTime)
{
- if (!MoverQuery.TryGetComponent(player, out var mover) ||
- !XformQuery.TryGetComponent(player, out var xform))
- {
- return;
- }
-
- var physicsUid = player;
- PhysicsComponent? body;
- var xformMover = xform;
-
- if (mover.ToParent && RelayQuery.HasComponent(xform.ParentUid))
- {
- if (!PhysicsQuery.TryGetComponent(xform.ParentUid, out body) ||
- !XformQuery.TryGetComponent(xform.ParentUid, out xformMover))
- {
- return;
- }
-
- physicsUid = xform.ParentUid;
- }
- else if (!PhysicsQuery.TryGetComponent(player, out body))
+ if (!MoverQuery.TryGetComponent(player, out var mover))
{
return;
}
// Server-side should just be handled on its own so we'll just do this shizznit
- HandleMobMovement(
- player,
- mover,
- physicsUid,
- body,
- xformMover,
- frameTime);
+ HandleMobMovement((player, mover), frameTime);
}
protected override bool CanSound()
if (!TryComp<StepTriggerComponent>(entity, out var comp))
return;
+ // Ensure we actually have the component
+ EnsureComp<TileFrictionModifierComponent>(entity);
+
// This is the base amount of reagent needed before a puddle can be considered slippery. Is defined based on
// the sprite threshold for a puddle larger than 5 pixels.
var smallPuddleThreshold = FixedPoint2.New(entity.Comp.OverflowVolume.Float() * LowThreshold);
if (solution.Volume <= smallPuddleThreshold)
{
_stepTrigger.SetActive(entity, false, comp);
- _tile.SetModifier(entity, TileFrictionController.DefaultFriction);
+ _tile.SetModifier(entity, 1f);
return;
}
// Lower tile friction based on how slippery it is, lets items slide across a puddle of lube
slipComp.SlipData.SlipFriction = (float)(puddleFriction/solution.Volume);
- _tile.SetModifier(entity, TileFrictionController.DefaultFriction * slipComp.SlipData.SlipFriction);
+ _tile.SetModifier(entity, slipComp.SlipData.SlipFriction);
Dirty(entity, slipComp);
}
{
var comp = EnsureComp<SpeedModifierContactsComponent>(uid);
var speed = 1 - maxViscosity;
- _speedModContacts.ChangeModifiers(uid, speed, comp);
+ _speedModContacts.ChangeSpeedModifiers(uid, speed, comp);
}
else
{
return true;
}
+ private HashSet<EntityUid> _moverAdded = new();
+ private List<Entity<InputMoverComponent>> _movers = new();
+
+ private void InsertMover(Entity<InputMoverComponent> source)
+ {
+ if (TryComp(source, out MovementRelayTargetComponent? relay))
+ {
+ if (TryComp(relay.Source, out InputMoverComponent? relayMover))
+ {
+ InsertMover((relay.Source, relayMover));
+ }
+ }
+
+ // Already added
+ if (!_moverAdded.Add(source.Owner))
+ return;
+
+ _movers.Add(source);
+ }
+
public override void UpdateBeforeSolve(bool prediction, float frameTime)
{
base.UpdateBeforeSolve(prediction, frameTime);
+ _moverAdded.Clear();
+ _movers.Clear();
var inputQueryEnumerator = AllEntityQuery<InputMoverComponent>();
+ // Need to order mob movement so that movers don't run before their relays.
while (inputQueryEnumerator.MoveNext(out var uid, out var mover))
{
- var physicsUid = uid;
-
- if (RelayQuery.HasComponent(uid))
- continue;
-
- if (!XformQuery.TryGetComponent(uid, out var xform))
- {
- continue;
- }
-
- PhysicsComponent? body;
- var xformMover = xform;
-
- if (mover.ToParent && RelayQuery.HasComponent(xform.ParentUid))
- {
- if (!PhysicsQuery.TryGetComponent(xform.ParentUid, out body) ||
- !XformQuery.TryGetComponent(xform.ParentUid, out xformMover))
- {
- continue;
- }
-
- physicsUid = xform.ParentUid;
- }
- else if (!PhysicsQuery.TryGetComponent(uid, out body))
- {
- continue;
- }
+ InsertMover((uid, mover));
+ }
- HandleMobMovement(uid,
- mover,
- physicsUid,
- body,
- xformMover,
- frameTime);
+ foreach (var mover in _movers)
+ {
+ HandleMobMovement(mover, frameTime);
}
HandleShuttleMovement(frameTime);
public static readonly CVarDef<bool> RelativeMovement =
CVarDef.Create("physics.relative_movement", true, CVar.ARCHIVE | CVar.REPLICATED | CVar.SERVER);
+ public static readonly CVarDef<float> MinFriction =
+ CVarDef.Create("physics.min_friction", 0.0f, CVar.ARCHIVE | CVar.REPLICATED | CVar.SERVER);
+
+ public static readonly CVarDef<float> AirFriction =
+ CVarDef.Create("physics.air_friction", 0.2f, CVar.ARCHIVE | CVar.REPLICATED | CVar.SERVER);
+
+ public static readonly CVarDef<float> OffgridFriction =
+ CVarDef.Create("physics.offgrid_friction", 0.05f, CVar.ARCHIVE | CVar.REPLICATED | CVar.SERVER);
+
public static readonly CVarDef<float> TileFrictionModifier =
- CVarDef.Create("physics.tile_friction", 40.0f, CVar.ARCHIVE | CVar.REPLICATED | CVar.SERVER);
+ CVarDef.Create("physics.tile_friction", 8.0f, CVar.ARCHIVE | CVar.REPLICATED | CVar.SERVER);
public static readonly CVarDef<float> StopSpeed =
CVarDef.Create("physics.stop_speed", 0.1f, CVar.ARCHIVE | CVar.REPLICATED | CVar.SERVER);
[DataField]
public bool MetamorphicChangeColor { get; private set; } = true;
-
/// <summary>
/// If not null, makes something slippery. Also defines slippery interactions like stun time and launch mult.
/// </summary>
using Robust.Shared.GameStates;
using Content.Shared.Clothing.EntitySystems;
-namespace Content.Shared.Clothing;
+namespace Content.Shared.Clothing.Components;
[RegisterComponent]
[NetworkedComponent]
/// <summary>
/// the levels of friction the wearer is subected to, higher the number the more friction.
/// </summary>
- [DataField, ViewVariables(VVAccess.ReadWrite)]
- public float Friction = 2.5f;
+ [DataField]
+ public float Friction = 0.125f;
/// <summary>
/// Determines the turning ability of the wearer, Higher the number the less control of their turning ability.
/// </summary>
- [DataField, ViewVariables(VVAccess.ReadWrite)]
- public float? FrictionNoInput = 2.5f;
+ [DataField]
+ public float FrictionNoInput = 0.125f;
/// <summary>
/// Sets the speed in which the wearer accelerates to full speed, higher the number the quicker the acceleration.
/// </summary>
- [DataField, ViewVariables(VVAccess.ReadWrite)]
- public float Acceleration = 5f;
+ [DataField]
+ public float Acceleration = 0.25f;
/// <summary>
/// The minimum speed the wearer needs to be traveling to take damage from collision.
/// </summary>
- [DataField, ViewVariables(VVAccess.ReadWrite)]
+ [DataField]
public float MinimumSpeed = 3f;
/// <summary>
/// The length of time the wearer is stunned for on collision.
/// </summary>
- [DataField, ViewVariables(VVAccess.ReadWrite)]
+ [DataField]
public float StunSeconds = 3f;
/// <summary>
/// The time duration before another collision can take place.
/// </summary>
- [DataField, ViewVariables(VVAccess.ReadWrite)]
+ [DataField]
public float DamageCooldown = 2f;
/// <summary>
/// The damage per increment of speed on collision.
/// </summary>
- [DataField, ViewVariables(VVAccess.ReadWrite)]
+ [DataField]
public float SpeedDamage = 1f;
-using Content.Shared.Inventory.Events;
using Content.Shared.Movement.Systems;
using Content.Shared.Damage.Systems;
-using Content.Shared.Movement.Components;
+using Content.Shared.Inventory;
+using Content.Shared.Clothing.Components;
-namespace Content.Shared.Clothing;
+namespace Content.Shared.Clothing.EntitySystems;
/// <summary>
/// Changes the friction and acceleration of the wearer and also the damage on impact variables of thew wearer when hitting a static object.
SubscribeLocalEvent<SkatesComponent, ClothingGotEquippedEvent>(OnGotEquipped);
SubscribeLocalEvent<SkatesComponent, ClothingGotUnequippedEvent>(OnGotUnequipped);
+ SubscribeLocalEvent<SkatesComponent, InventoryRelayedEvent<RefreshFrictionModifiersEvent>>(OnRefreshFrictionModifiers);
}
/// <summary>
/// When item is unequipped from the shoe slot, friction, aceleration and collide on impact return to default settings.
/// </summary>
- public void OnGotUnequipped(EntityUid uid, SkatesComponent component, ClothingGotUnequippedEvent args)
+ private void OnGotUnequipped(Entity<SkatesComponent> entity, ref ClothingGotUnequippedEvent args)
{
- if (!TryComp(args.Wearer, out MovementSpeedModifierComponent? speedModifier))
- return;
-
- _move.ChangeFriction(args.Wearer, MovementSpeedModifierComponent.DefaultFriction, MovementSpeedModifierComponent.DefaultFrictionNoInput, MovementSpeedModifierComponent.DefaultAcceleration, speedModifier);
- _impact.ChangeCollide(args.Wearer, component.DefaultMinimumSpeed, component.DefaultStunSeconds, component.DefaultDamageCooldown, component.DefaultSpeedDamage);
+ _move.RefreshFrictionModifiers(args.Wearer);
+ _impact.ChangeCollide(args.Wearer, entity.Comp.DefaultMinimumSpeed, entity.Comp.DefaultStunSeconds, entity.Comp.DefaultDamageCooldown, entity.Comp.DefaultSpeedDamage);
}
/// <summary>
/// When item is equipped into the shoe slot, friction, acceleration and collide on impact are adjusted.
/// </summary>
- private void OnGotEquipped(EntityUid uid, SkatesComponent component, ClothingGotEquippedEvent args)
+ private void OnGotEquipped(Entity<SkatesComponent> entity, ref ClothingGotEquippedEvent args)
+ {
+ _move.RefreshFrictionModifiers(args.Wearer);
+ _impact.ChangeCollide(args.Wearer, entity.Comp.MinimumSpeed, entity.Comp.StunSeconds, entity.Comp.DamageCooldown, entity.Comp.SpeedDamage);
+ }
+
+ private void OnRefreshFrictionModifiers(Entity<SkatesComponent> ent,
+ ref InventoryRelayedEvent<RefreshFrictionModifiersEvent> args)
{
- _move.ChangeFriction(args.Wearer, component.Friction, component.FrictionNoInput, component.Acceleration);
- _impact.ChangeCollide(args.Wearer, component.MinimumSpeed, component.StunSeconds, component.DamageCooldown, component.SpeedDamage);
+ args.Args.ModifyFriction(ent.Comp.Friction, ent.Comp.FrictionNoInput);
+ args.Args.ModifyAcceleration(ent.Comp.Acceleration);
}
}
if (!EntityManager.HasComponent<DamageableComponent>(uid))
return;
+ //TODO: This should solve after physics solves
var speed = args.OurBody.LinearVelocity.Length();
if (speed < component.MinimumSpeed)
using System.Numerics;
using Content.Shared.CCVar;
using Content.Shared.Gravity;
+using Content.Shared.Interaction.Events;
using Content.Shared.Movement.Events;
using Content.Shared.Movement.Pulling.Components;
using Content.Shared.Movement.Systems;
using Robust.Shared.Configuration;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
+using Robust.Shared.Physics;
using Robust.Shared.Physics.Components;
using Robust.Shared.Physics.Controllers;
using Robust.Shared.Physics.Dynamics;
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
[Dependency] private readonly SharedGravitySystem _gravity = default!;
[Dependency] private readonly SharedMoverController _mover = default!;
- [Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly SharedMapSystem _map = default!;
private EntityQuery<TileFrictionModifierComponent> _frictionQuery;
private EntityQuery<PullableComponent> _pullableQuery;
private EntityQuery<MapGridComponent> _gridQuery;
- private float _stopSpeed;
private float _frictionModifier;
- public const float DefaultFriction = 0.3f;
+ private float _minDamping;
+ private float _airDamping;
+ private float _offGridDamping;
public override void Initialize()
{
base.Initialize();
Subs.CVar(_configManager, CCVars.TileFrictionModifier, value => _frictionModifier = value, true);
- Subs.CVar(_configManager, CCVars.StopSpeed, value => _stopSpeed = value, true);
+ Subs.CVar(_configManager, CCVars.MinFriction, value => _minDamping = value, true);
+ Subs.CVar(_configManager, CCVars.AirFriction, value => _airDamping = value, true);
+ Subs.CVar(_configManager, CCVars.OffgridFriction, value => _offGridDamping = value, true);
_frictionQuery = GetEntityQuery<TileFrictionModifierComponent>();
_xformQuery = GetEntityQuery<TransformComponent>();
_pullerQuery = GetEntityQuery<PullerComponent>();
var uid = body.Owner;
// Only apply friction when it's not a mob (or the mob doesn't have control)
- if (prediction && !body.Predict ||
- body.BodyStatus == BodyStatus.InAir ||
- _mover.UseMobMovement(uid))
- {
+ // We may want to instead only apply friction to dynamic entities and not mobs ever.
+ if (prediction && !body.Predict || _mover.UseMobMovement(uid))
continue;
- }
if (body.LinearVelocity.Equals(Vector2.Zero) && body.AngularVelocity.Equals(0f))
continue;
continue;
}
- var surfaceFriction = GetTileFriction(uid, body, xform);
+ float friction;
+
+ // If we're not touching the ground, don't use tileFriction.
+ // TODO: Make IsWeightless event-based; we already have grid traversals tracked so just raise events
+ if (body.BodyStatus == BodyStatus.InAir || _gravity.IsWeightless(uid, body, xform) || !xform.Coordinates.IsValid(EntityManager))
+ friction = xform.GridUid == null || !_gridQuery.HasComp(xform.GridUid) ? _offGridDamping : _airDamping;
+ else
+ friction = _frictionModifier * GetTileFriction(uid, body, xform);
+
var bodyModifier = 1f;
if (_frictionQuery.TryGetComponent(uid, out var frictionComp))
bodyModifier *= 0.2f;
}
- var friction = _frictionModifier * surfaceFriction * bodyModifier;
+ friction *= bodyModifier;
- ReduceLinearVelocity(uid, prediction, body, friction, frameTime);
- ReduceAngularVelocity(uid, prediction, body, friction, frameTime);
- }
- }
+ friction = Math.Max(_minDamping, friction);
- private void ReduceLinearVelocity(EntityUid uid, bool prediction, PhysicsComponent body, float friction, float frameTime)
- {
- var speed = body.LinearVelocity.Length();
+ PhysicsSystem.SetLinearDamping(uid, body, friction);
+ PhysicsSystem.SetAngularDamping(uid, body, friction);
- if (speed <= 0.0f)
- return;
+ if (body.BodyType != BodyType.KinematicController)
+ return;
- // This is the *actual* amount that speed will drop by, we just do some multiplication around it to be easier.
- var drop = 0.0f;
- float control;
-
- if (friction > 0.0f)
- {
- // TBH I can't really tell if this makes a difference.
- if (!prediction)
- {
- control = speed < _stopSpeed ? _stopSpeed : speed;
- }
- else
- {
- control = speed;
- }
-
- drop += control * friction * frameTime;
+ // Physics engine doesn't apply damping to Kinematic Controllers so we have to do it here.
+ // BEWARE YE TRAVELLER:
+ // You may think you can just pass the body.LinearVelocity to the Friction function and edit it there!
+ // But doing so is unpredicted! And you will doom yourself to 1000 years of rubber banding!
+ var velocity = body.LinearVelocity;
+ _mover.Friction(0f, frameTime, friction, ref velocity);
+ PhysicsSystem.SetLinearVelocity(uid, velocity, body: body);
}
-
- var newSpeed = MathF.Max(0.0f, speed - drop);
-
- newSpeed /= speed;
- _physics.SetLinearVelocity(uid, body.LinearVelocity * newSpeed, body: body);
- }
-
- private void ReduceAngularVelocity(EntityUid uid, bool prediction, PhysicsComponent body, float friction, float frameTime)
- {
- var speed = MathF.Abs(body.AngularVelocity);
-
- if (speed <= 0.0f)
- return;
-
- // This is the *actual* amount that speed will drop by, we just do some multiplication around it to be easier.
- var drop = 0.0f;
- float control;
-
- if (friction > 0.0f)
- {
- // TBH I can't really tell if this makes a difference.
- if (!prediction)
- {
- control = speed < _stopSpeed ? _stopSpeed : speed;
- }
- else
- {
- control = speed;
- }
-
- drop += control * friction * frameTime;
- }
-
- var newSpeed = MathF.Max(0.0f, speed - drop);
-
- newSpeed /= speed;
- _physics.SetAngularVelocity(uid, body.AngularVelocity * newSpeed, body: body);
}
[Pure]
PhysicsComponent body,
TransformComponent xform)
{
- // TODO: Make IsWeightless event-based; we already have grid traversals tracked so just raise events
- if (_gravity.IsWeightless(uid, body, xform))
- return 0.0f;
-
- if (!xform.Coordinates.IsValid(EntityManager))
- return 0.0f;
-
- // If not on a grid then return the map's friction.
+ var tileModifier = 1f;
+ // If not on a grid and not in the air then return the map's friction.
if (!_gridQuery.TryGetComponent(xform.GridUid, out var grid))
{
return _frictionQuery.TryGetComponent(xform.MapUid, out var friction)
? friction.Modifier
- : DefaultFriction;
+ : tileModifier;
}
var tile = _map.GetTileRef(xform.GridUid.Value, grid, xform.Coordinates);
if (tile.Tile.IsEmpty &&
HasComp<MapComponent>(xform.GridUid) &&
(!TryComp<GravityComponent>(xform.GridUid, out var gravity) || gravity.Enabled))
- {
- return DefaultFriction;
- }
-
- // If there's an anchored ent that modifies friction then fallback to that instead.
- var anc = grid.GetAnchoredEntitiesEnumerator(tile.GridIndices);
+ return tileModifier;
+ // Check for anchored ents that modify friction
+ var anc = _map.GetAnchoredEntitiesEnumerator(xform.GridUid.Value, grid, tile.GridIndices);
while (anc.MoveNext(out var tileEnt))
{
if (_frictionQuery.TryGetComponent(tileEnt, out var friction))
- return friction.Modifier;
+ tileModifier *= friction.Modifier;
}
var tileDef = _tileDefinitionManager[tile.Tile.TypeId];
- return tileDef.Friction;
+ return tileDef.Friction * tileModifier;
}
public void SetModifier(EntityUid entityUid, float value, TileFrictionModifierComponent? friction = null)
SubscribeLocalEvent<InventoryComponent, ZombificationResistanceQueryEvent>(RelayInventoryEvent);
// by-ref events
+ SubscribeLocalEvent<InventoryComponent, RefreshFrictionModifiersEvent>(RefRelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, BeforeStaminaDamageEvent>(RefRelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, GetExplosionResistanceEvent>(RefRelayInventoryEvent);
SubscribeLocalEvent<InventoryComponent, IsWeightlessEvent>(RefRelayInventoryEvent);
/// </summary>
[DataField("barestepSounds")] public SoundSpecifier? BarestepSounds { get; private set; } = new SoundCollectionSpecifier("BarestepHard");
- [DataField("friction")] public float Friction { get; set; } = 0.2f;
+ /// <summary>
+ /// Base friction modifier for this tile.
+ /// </summary>
+ [DataField("friction")] public float Friction { get; set; } = 1f;
[DataField("variants")] public byte Variants { get; set; } = 1;
[DataField("mobFriction")]
public float? MobFriction { get; private set; }
- /// <summary>
- /// No-input friction override for mob mover in <see cref="SharedMoverController"/>
- /// </summary>
- [DataField("mobFrictionNoInput")]
- public float? MobFrictionNoInput { get; private set; }
-
/// <summary>
/// Accel override for mob mover in <see cref="SharedMoverController"/>
/// </summary>
/// </summary>
[DataField, ViewVariables(VVAccess.ReadWrite)]
[AutoNetworkedField]
- public float MobFriction = 0.5f;
+ public float MobFriction = 0.05f;
/// <summary>
/// Modified mob friction without input while on FrictionContactsComponent
/// </summary>
[AutoNetworkedField]
[DataField, ViewVariables(VVAccess.ReadWrite)]
- public float MobFrictionNoInput = 0.05f;
+ public float? MobFrictionNoInput = 0.05f;
/// <summary>
/// Modified mob acceleration while on FrictionContactsComponent
/// </summary>
[AutoNetworkedField]
[DataField, ViewVariables(VVAccess.ReadWrite)]
- public float MobAcceleration = 2.0f;
+ public float MobAcceleration = 0.1f;
}
// (well maybe we do but the code is designed such that MoverSystem applies movement speed)
// (and I'm not changing that)
- /// <summary>
- /// Should our velocity be applied to our parent?
- /// </summary>
- [DataField]
- public bool ToParent = false;
-
public GameTick LastInputTick;
public ushort LastInputSubTick;
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
public sealed partial class JetpackComponent : Component
{
+ [DataField, AutoNetworkedField]
+ public EntityUid? JetpackUser;
+
[ViewVariables(VVAccess.ReadWrite), DataField("moleUsage")]
public float MoleUsage = 0.012f;
public float Acceleration = 1f;
[ViewVariables(VVAccess.ReadWrite), DataField("friction")]
- public float Friction = 0.3f;
+ public float Friction = 0.25f; // same as off-grid friction
[ViewVariables(VVAccess.ReadWrite), DataField("weightlessModifier")]
public float WeightlessModifier = 1.2f;
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
public sealed partial class JetpackUserComponent : Component
{
- [AutoNetworkedField]
+ [DataField, AutoNetworkedField]
public EntityUid Jetpack;
+
+ [DataField, AutoNetworkedField]
+ public float WeightlessAcceleration;
+
+ [DataField, AutoNetworkedField]
+ public float WeightlessFriction;
+
+ [DataField, AutoNetworkedField]
+ public float WeightlessFrictionNoInput;
+
+ [DataField, AutoNetworkedField]
+ public float WeightlessModifier;
}
public sealed partial class SpeedModifiedByContactComponent : Component
{
}
+
+[NetworkedComponent, RegisterComponent] // ditto but for friction
+public sealed partial class FrictionModifiedByContactComponent : Component
+{
+}
/// <summary>
/// The entity that is relaying to this entity.
/// </summary>
- [ViewVariables, AutoNetworkedField]
+ [DataField, AutoNetworkedField]
public EntityUid Source;
}
[Access(typeof(MovementSpeedModifierSystem))]
public sealed partial class MovementSpeedModifierComponent : Component
{
- // Weightless
- public const float DefaultMinimumFrictionSpeed = 0.005f;
+ #region defaults
+
+ // weightless
public const float DefaultWeightlessFriction = 1f;
- public const float DefaultWeightlessFrictionNoInput = 0.2f;
- public const float DefaultOffGridFriction = 0.05f;
public const float DefaultWeightlessModifier = 0.7f;
public const float DefaultWeightlessAcceleration = 1f;
+ // friction
public const float DefaultAcceleration = 20f;
- public const float DefaultFriction = 20f;
- public const float DefaultFrictionNoInput = 20f;
+ public const float DefaultFriction = 2.5f;
+ public const float DefaultFrictionNoInput = 2.5f;
+ public const float DefaultMinimumFrictionSpeed = 0.005f;
+ // movement
public const float DefaultBaseWalkSpeed = 2.5f;
public const float DefaultBaseSprintSpeed = 4.5f;
- [AutoNetworkedField, ViewVariables]
- public float WalkSpeedModifier = 1.0f;
+ #endregion
- [AutoNetworkedField, ViewVariables]
- public float SprintSpeedModifier = 1.0f;
+ #region base values
+
+ /// <summary>
+ /// These base values should be defined in yaml and rarely if ever modified directly.
+ /// </summary>
+ [DataField, AutoNetworkedField]
+ public float BaseWalkSpeed = DefaultBaseWalkSpeed;
+
+ [DataField, AutoNetworkedField]
+ public float BaseSprintSpeed = DefaultBaseSprintSpeed;
+
+ /// <summary>
+ /// The acceleration applied to mobs when moving. If this is ever less than Friction the mob will be slower.
+ /// </summary>
+ [AutoNetworkedField, DataField]
+ public float BaseAcceleration = DefaultAcceleration;
+
+ /// <summary>
+ /// The body's base friction modifier that is applied in *all* circumstances.
+ /// </summary>
+ [AutoNetworkedField, DataField]
+ public float BaseFriction = DefaultFriction;
/// <summary>
/// Minimum speed a mob has to be moving before applying movement friction.
/// </summary>
- [ViewVariables(VVAccess.ReadWrite), DataField]
+ [DataField]
public float MinimumFrictionSpeed = DefaultMinimumFrictionSpeed;
+ #endregion
+
+ #region calculated values
+
+ [ViewVariables]
+ public float CurrentWalkSpeed => WalkSpeedModifier * BaseWalkSpeed;
+ [ViewVariables]
+ public float CurrentSprintSpeed => SprintSpeedModifier * BaseSprintSpeed;
+
/// <summary>
- /// The negative velocity applied for friction when weightless and providing inputs.
+ /// The acceleration applied to mobs when moving. If this is ever less than Friction the mob will be slower.
/// </summary>
- [ViewVariables(VVAccess.ReadWrite), DataField]
- public float WeightlessFriction = DefaultWeightlessFriction;
+ [AutoNetworkedField, DataField]
+ public float Acceleration;
/// <summary>
- /// The negative velocity applied for friction when weightless and not providing inputs.
- /// This is essentially how much their speed decreases per second.
+ /// Modifier to the negative velocity applied for friction.
/// </summary>
- [ViewVariables(VVAccess.ReadWrite), DataField]
- public float WeightlessFrictionNoInput = DefaultWeightlessFrictionNoInput;
+ [AutoNetworkedField, DataField]
+ public float Friction;
/// <summary>
- /// The negative velocity applied for friction when weightless and not standing on a grid or mapgrid
+ /// The negative velocity applied for friction.
/// </summary>
- [ViewVariables(VVAccess.ReadWrite), DataField]
- public float OffGridFriction = DefaultOffGridFriction;
+ [AutoNetworkedField, DataField]
+ public float FrictionNoInput;
+
+ #endregion
+
+ #region movement modifiers
+
+ [AutoNetworkedField, ViewVariables]
+ public float WalkSpeedModifier = 1.0f;
+
+ [AutoNetworkedField, ViewVariables]
+ public float SprintSpeedModifier = 1.0f;
+
+ #endregion
+
+ #region Weightless
/// <summary>
- /// The movement speed modifier applied to a mob's total input velocity when weightless.
+ /// These base values should be defined in yaml and rarely if ever modified directly.
/// </summary>
- [ViewVariables(VVAccess.ReadWrite), DataField]
- public float WeightlessModifier = DefaultWeightlessModifier;
+ [AutoNetworkedField, DataField]
+ public float BaseWeightlessFriction = DefaultWeightlessFriction;
+
+ [AutoNetworkedField, DataField]
+ public float BaseWeightlessModifier = DefaultWeightlessModifier;
+
+ [AutoNetworkedField, DataField]
+ public float BaseWeightlessAcceleration = DefaultWeightlessAcceleration;
+
+ /*
+ * Final values
+ */
+
+ [ViewVariables]
+ public float WeightlessWalkSpeed => WeightlessModifier * BaseWalkSpeed;
+ [ViewVariables]
+ public float WeightlessSprintSpeed => WeightlessModifier * BaseSprintSpeed;
/// <summary>
/// The acceleration applied to mobs when moving and weightless.
/// </summary>
- [ViewVariables(VVAccess.ReadWrite), DataField]
- public float WeightlessAcceleration = DefaultWeightlessAcceleration;
+ [AutoNetworkedField, DataField]
+ public float WeightlessAcceleration;
/// <summary>
- /// The acceleration applied to mobs when moving.
+ /// The movement speed modifier applied to a mob's total input velocity when weightless.
/// </summary>
- [AutoNetworkedField, ViewVariables(VVAccess.ReadWrite), DataField]
- public float Acceleration = DefaultAcceleration;
+ [AutoNetworkedField, DataField]
+ public float WeightlessModifier;
/// <summary>
- /// The negative velocity applied for friction.
+ /// The negative velocity applied for friction when weightless and providing inputs.
/// </summary>
- [AutoNetworkedField, ViewVariables(VVAccess.ReadWrite), DataField]
- public float Friction = DefaultFriction;
+ [AutoNetworkedField, DataField]
+ public float WeightlessFriction;
/// <summary>
- /// The negative velocity applied for friction.
+ /// The negative velocity applied for friction when weightless and not providing inputs.
/// </summary>
- [AutoNetworkedField, ViewVariables(VVAccess.ReadWrite), DataField]
- public float? FrictionNoInput;
-
- [ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
- public float BaseWalkSpeed { get; set; } = DefaultBaseWalkSpeed;
+ [AutoNetworkedField, DataField]
+ public float WeightlessFrictionNoInput;
- [ViewVariables(VVAccess.ReadWrite), DataField, AutoNetworkedField]
- public float BaseSprintSpeed { get; set; } = DefaultBaseSprintSpeed;
+ /// <summary>
+ /// The negative velocity applied for friction when weightless and not standing on a grid or mapgrid
+ /// </summary>
+ [AutoNetworkedField, DataField]
+ public float? OffGridFriction;
- [ViewVariables]
- public float CurrentWalkSpeed => WalkSpeedModifier * BaseWalkSpeed;
- [ViewVariables]
- public float CurrentSprintSpeed => SprintSpeedModifier * BaseSprintSpeed;
+ #endregion
}
}
[Access(typeof(SharedMoverController))]
public sealed partial class RelayInputMoverComponent : Component
{
- [ViewVariables, AutoNetworkedField]
+ [DataField, AutoNetworkedField]
public EntityUid RelayEntity;
}
[Dependency] private readonly MovementSpeedModifierSystem _speedModifierSystem = default!;
// Comment copied from "original" SlowContactsSystem.cs (now SpeedModifierContactsSystem.cs)
- // TODO full-game-save
+ // TODO full-game-save
// Either these need to be processed before a map is saved, or slowed/slowing entities need to update on init.
- private HashSet<EntityUid> _toUpdate = new();
+ private readonly HashSet<EntityUid> _toUpdate = new();
+ private readonly HashSet<EntityUid> _toRemove = new();
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<FrictionContactsComponent, StartCollideEvent>(OnEntityEnter);
SubscribeLocalEvent<FrictionContactsComponent, EndCollideEvent>(OnEntityExit);
+ SubscribeLocalEvent<FrictionModifiedByContactComponent, RefreshFrictionModifiersEvent>(OnRefreshFrictionModifiers);
SubscribeLocalEvent<FrictionContactsComponent, ComponentShutdown>(OnShutdown);
UpdatesAfter.Add(typeof(SharedPhysicsSystem));
}
- private void OnEntityEnter(EntityUid uid, FrictionContactsComponent component, ref StartCollideEvent args)
+ public override void Update(float frameTime)
{
- var otherUid = args.OtherEntity;
+ base.Update(frameTime);
- if (!HasComp(otherUid, typeof(MovementSpeedModifierComponent)))
- return;
+ _toRemove.Clear();
- _toUpdate.Add(otherUid);
+ foreach (var ent in _toUpdate)
+ {
+ _speedModifierSystem.RefreshFrictionModifiers(ent);
+ }
+
+ foreach (var ent in _toRemove)
+ {
+ RemComp<FrictionModifiedByContactComponent>(ent);
+ }
+
+ _toUpdate.Clear();
}
- private void OnEntityExit(EntityUid uid, FrictionContactsComponent component, ref EndCollideEvent args)
+ public void ChangeFrictionModifiers(EntityUid uid, float friction, FrictionContactsComponent? component = null)
{
- var otherUid = args.OtherEntity;
+ ChangeFrictionModifiers(uid, friction, null, null, component);
+ }
- if (!HasComp(otherUid, typeof(MovementSpeedModifierComponent)))
+ public void ChangeFrictionModifiers(EntityUid uid, float mobFriction, float? mobFrictionNoInput, float? acceleration, FrictionContactsComponent? component = null)
+ {
+ if (!Resolve(uid, ref component))
return;
- _toUpdate.Add(otherUid);
+ component.MobFriction = mobFriction;
+ component.MobFrictionNoInput = mobFrictionNoInput;
+ if (acceleration.HasValue)
+ component.MobAcceleration = acceleration.Value;
+ Dirty(uid, component);
+ _toUpdate.UnionWith(_physics.GetContactingEntities(uid));
}
private void OnShutdown(EntityUid uid, FrictionContactsComponent component, ComponentShutdown args)
if (!TryComp(uid, out PhysicsComponent? phys))
return;
+ // Note that the entity may not be getting deleted here. E.g., glue puddles.
_toUpdate.UnionWith(_physics.GetContactingEntities(uid, phys));
}
- public override void Update(float frameTime)
- {
- base.Update(frameTime);
-
- foreach (var uid in _toUpdate)
- {
- ApplyFrictionChange(uid);
- }
-
- _toUpdate.Clear();
- }
-
- private void ApplyFrictionChange(EntityUid uid)
+ private void OnRefreshFrictionModifiers(Entity<FrictionModifiedByContactComponent> entity, ref RefreshFrictionModifiersEvent args)
{
- if (!EntityManager.TryGetComponent<PhysicsComponent>(uid, out var physicsComponent))
- return;
-
- if (!TryComp(uid, out MovementSpeedModifierComponent? speedModifier))
+ if (!EntityManager.TryGetComponent<PhysicsComponent>(entity, out var physicsComponent))
return;
- FrictionContactsComponent? frictionComponent = TouchesFrictionContactsComponent(uid, physicsComponent);
+ var friction = 0.0f;
+ var frictionNoInput = 0.0f;
+ var acceleration = 0.0f;
- if (frictionComponent == null)
+ var remove = true;
+ var entries = 0;
+ foreach (var ent in _physics.GetContactingEntities(entity, physicsComponent))
{
- _speedModifierSystem.ChangeFriction(uid, MovementSpeedModifierComponent.DefaultFriction, null, MovementSpeedModifierComponent.DefaultAcceleration, speedModifier);
+ if (!TryComp<FrictionContactsComponent>(ent, out var contacts))
+ continue;
+ friction += contacts.MobFriction;
+ frictionNoInput += contacts.MobFrictionNoInput ?? contacts.MobFriction;
+ acceleration += contacts.MobAcceleration;
+ remove = false;
+ entries++;
}
- else
+
+ if (entries > 0)
{
- _speedModifierSystem.ChangeFriction(uid, frictionComponent.MobFriction, frictionComponent.MobFrictionNoInput, frictionComponent.MobAcceleration, speedModifier);
+ if (!MathHelper.CloseTo(friction, entries) || !MathHelper.CloseTo(frictionNoInput, entries))
+ {
+ friction /= entries;
+ frictionNoInput /= entries;
+ args.ModifyFriction(friction, frictionNoInput);
+ }
+
+ if (!MathHelper.CloseTo(acceleration, entries))
+ {
+ acceleration /= entries;
+ args.ModifyAcceleration(acceleration);
+ }
}
+
+ // no longer colliding with anything
+ if (remove)
+ _toRemove.Add(entity);
}
- private FrictionContactsComponent? TouchesFrictionContactsComponent(EntityUid uid, PhysicsComponent physicsComponent)
+ private void OnEntityExit(EntityUid uid, FrictionContactsComponent component, ref EndCollideEvent args)
{
- foreach (var ent in _physics.GetContactingEntities(uid, physicsComponent))
- {
- if (!TryComp(ent, out FrictionContactsComponent? frictionContacts))
- continue;
+ var otherUid = args.OtherEntity;
+ _toUpdate.Add(otherUid);
+ }
- return frictionContacts;
- }
+ private void OnEntityEnter(EntityUid uid, FrictionContactsComponent component, ref StartCollideEvent args)
+ {
+ AddModifiedEntity(args.OtherEntity);
+ }
+
+ public void AddModifiedEntity(EntityUid uid)
+ {
+ if (!HasComp<MovementSpeedModifierComponent>(uid))
+ return;
- return null;
+ EnsureComp<FrictionModifiedByContactComponent>(uid);
+ _toUpdate.Add(uid);
}
}
+using System.Text.Json.Serialization.Metadata;
+using Content.Shared.CCVar;
using Content.Shared.Inventory;
using Content.Shared.Movement.Components;
+using Content.Shared.Movement.Events;
+using Robust.Shared.Configuration;
using Robust.Shared.Timing;
namespace Content.Shared.Movement.Systems
public sealed class MovementSpeedModifierSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _timing = default!;
+ [Dependency] private readonly IConfigurationManager _configManager = default!;
+
+ private float _frictionModifier;
+ private float _airDamping;
+ private float _offGridDamping;
+
+ public override void Initialize()
+ {
+ base.Initialize();
+ SubscribeLocalEvent<MovementSpeedModifierComponent, MapInitEvent>(OnModMapInit);
+
+ Subs.CVar(_configManager, CCVars.TileFrictionModifier, value => _frictionModifier = value, true);
+ Subs.CVar(_configManager, CCVars.AirFriction, value => _airDamping = value, true);
+ Subs.CVar(_configManager, CCVars.OffgridFriction, value => _offGridDamping = value, true);
+ }
+
+ private void OnModMapInit(Entity<MovementSpeedModifierComponent> ent, ref MapInitEvent args)
+ {
+ // TODO: Dirty these smarter.
+ ent.Comp.WeightlessAcceleration = ent.Comp.BaseWeightlessAcceleration;
+ ent.Comp.WeightlessModifier = ent.Comp.BaseWeightlessModifier;
+ ent.Comp.WeightlessFriction = _airDamping * ent.Comp.BaseWeightlessFriction;
+ ent.Comp.WeightlessFrictionNoInput = _airDamping * ent.Comp.BaseWeightlessFriction;
+ ent.Comp.OffGridFriction = _offGridDamping * ent.Comp.BaseWeightlessFriction;
+ ent.Comp.Acceleration = ent.Comp.BaseAcceleration;
+ ent.Comp.Friction = _frictionModifier * ent.Comp.BaseFriction;
+ ent.Comp.FrictionNoInput = _frictionModifier * ent.Comp.BaseFriction;
+ Dirty(ent);
+ }
+
+ public void RefreshWeightlessModifiers(EntityUid uid, MovementSpeedModifierComponent? move = null)
+ {
+ if (!Resolve(uid, ref move, false))
+ return;
+
+ if (_timing.ApplyingState)
+ return;
+
+ var ev = new RefreshWeightlessModifiersEvent()
+ {
+ WeightlessAcceleration = move.BaseWeightlessAcceleration,
+ WeightlessAccelerationMod = 1.0f,
+ WeightlessModifier = move.BaseWeightlessModifier,
+ WeightlessFriction = move.BaseWeightlessFriction,
+ WeightlessFrictionMod = 1.0f,
+ WeightlessFrictionNoInput = move.BaseWeightlessFriction,
+ WeightlessFrictionNoInputMod = 1.0f,
+ };
+
+ RaiseLocalEvent(uid, ref ev);
+
+ if (MathHelper.CloseTo(ev.WeightlessAcceleration, move.WeightlessAcceleration) &&
+ MathHelper.CloseTo(ev.WeightlessModifier, move.WeightlessModifier) &&
+ MathHelper.CloseTo(ev.WeightlessFriction, move.WeightlessFriction) &&
+ MathHelper.CloseTo(ev.WeightlessFrictionNoInput, move.WeightlessFrictionNoInput))
+ {
+ return;
+ }
+
+ move.WeightlessAcceleration = ev.WeightlessAcceleration * ev.WeightlessAccelerationMod;
+ move.WeightlessModifier = ev.WeightlessModifier;
+ move.WeightlessFriction = _airDamping * ev.WeightlessFriction * ev.WeightlessFrictionMod;
+ move.WeightlessFrictionNoInput = _airDamping * ev.WeightlessFrictionNoInput * ev.WeightlessFrictionNoInputMod;
+ Dirty(uid, move);
+ }
public void RefreshMovementSpeedModifiers(EntityUid uid, MovementSpeedModifierComponent? move = null)
{
Dirty(uid, move);
}
- // We might want to create separate RefreshMovementFrictionModifiersEvent and RefreshMovementFrictionModifiers function that will call it
- public void ChangeFriction(EntityUid uid, float friction, float? frictionNoInput, float acceleration, MovementSpeedModifierComponent? move = null)
+ public void RefreshFrictionModifiers(EntityUid uid, MovementSpeedModifierComponent? move = null)
+ {
+ if (!Resolve(uid, ref move, false))
+ return;
+
+ if (_timing.ApplyingState)
+ return;
+
+ var ev = new RefreshFrictionModifiersEvent()
+ {
+ Friction = move.BaseFriction,
+ FrictionNoInput = move.BaseFriction,
+ Acceleration = move.BaseAcceleration,
+ };
+ RaiseLocalEvent(uid, ref ev);
+
+ if (MathHelper.CloseTo(ev.Friction, move.Friction)
+ && MathHelper.CloseTo(ev.FrictionNoInput, move.FrictionNoInput)
+ && MathHelper.CloseTo(ev.Acceleration, move.Acceleration))
+ return;
+
+ move.Friction = _frictionModifier * ev.Friction;
+ move.FrictionNoInput = _frictionModifier * ev.FrictionNoInput;
+ move.Acceleration = ev.Acceleration;
+
+ Dirty(uid, move);
+ }
+
+ public void ChangeBaseFriction(EntityUid uid, float friction, float frictionNoInput, float acceleration, MovementSpeedModifierComponent? move = null)
{
if (!Resolve(uid, ref move, false))
return;
- move.Friction = friction;
+ move.BaseFriction = friction;
move.FrictionNoInput = frictionNoInput;
- move.Acceleration = acceleration;
+ move.BaseAcceleration = acceleration;
Dirty(uid, move);
}
}
ModifySpeed(mod, mod);
}
}
+
+ [ByRefEvent]
+ public record struct RefreshWeightlessModifiersEvent
+ {
+ public float WeightlessAcceleration;
+ public float WeightlessAccelerationMod;
+
+ public float WeightlessModifier;
+
+ public float WeightlessFriction;
+ public float WeightlessFrictionMod;
+
+ public float WeightlessFrictionNoInput;
+ public float WeightlessFrictionNoInputMod;
+
+ public void ModifyFriction(float friction, float noInput)
+ {
+ WeightlessFrictionMod *= friction;
+ WeightlessFrictionNoInput *= noInput;
+ }
+
+ public void ModifyFriction(float friction)
+ {
+ ModifyFriction(friction, friction);
+ }
+
+ public void ModifyAcceleration(float acceleration, float modifier)
+ {
+ WeightlessAcceleration *= acceleration;
+ WeightlessModifier *= modifier;
+ }
+
+ public void ModifyAcceleration(float modifier)
+ {
+ ModifyAcceleration(modifier, modifier);
+ }
+ }
+ [ByRefEvent]
+ public record struct RefreshFrictionModifiersEvent : IInventoryRelayEvent
+ {
+ public float Friction;
+ public float FrictionNoInput;
+ public float Acceleration;
+
+ public void ModifyFriction(float friction, float noInput)
+ {
+ Friction *= friction;
+ FrictionNoInput *= noInput;
+ }
+
+ public void ModifyFriction(float friction)
+ {
+ ModifyFriction(friction, friction);
+ }
+
+ public void ModifyAcceleration(float acceleration)
+ {
+ Acceleration *= acceleration;
+ }
+ SlotFlags IInventoryRelayEvent.TargetSlots => ~SlotFlags.POCKET;
+ }
}
[Dependency] private readonly MovementSpeedModifierSystem _movementSpeedModifier = default!;
[Dependency] protected readonly SharedAppearanceSystem Appearance = default!;
[Dependency] protected readonly SharedContainerSystem Container = default!;
- [Dependency] private readonly SharedMoverController _mover = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly ActionContainerSystem _actionContainer = default!;
SubscribeLocalEvent<JetpackComponent, GetItemActionsEvent>(OnJetpackGetAction);
SubscribeLocalEvent<JetpackComponent, DroppedEvent>(OnJetpackDropped);
SubscribeLocalEvent<JetpackComponent, ToggleJetpackEvent>(OnJetpackToggle);
- SubscribeLocalEvent<JetpackComponent, CanWeightlessMoveEvent>(OnJetpackCanWeightlessMove);
+ SubscribeLocalEvent<JetpackUserComponent, RefreshWeightlessModifiersEvent>(OnJetpackUserWeightlessMovement);
SubscribeLocalEvent<JetpackUserComponent, CanWeightlessMoveEvent>(OnJetpackUserCanWeightless);
SubscribeLocalEvent<JetpackUserComponent, EntParentChangedMessage>(OnJetpackUserEntParentChanged);
+ SubscribeLocalEvent<JetpackComponent, EntGotInsertedIntoContainerMessage>(OnJetpackMoved);
SubscribeLocalEvent<GravityChangedEvent>(OnJetpackUserGravityChanged);
SubscribeLocalEvent<JetpackComponent, MapInitEvent>(OnMapInit);
}
- private void OnMapInit(EntityUid uid, JetpackComponent component, MapInitEvent args)
+ private void OnJetpackUserWeightlessMovement(Entity<JetpackUserComponent> ent, ref RefreshWeightlessModifiersEvent args)
{
- _actionContainer.EnsureAction(uid, ref component.ToggleActionEntity, component.ToggleAction);
- Dirty(uid, component);
+ // Yes this bulldozes the values but primarily for backwards compat atm.
+ args.WeightlessAcceleration = ent.Comp.WeightlessAcceleration;
+ args.WeightlessModifier = ent.Comp.WeightlessModifier;
+ args.WeightlessFriction = ent.Comp.WeightlessFriction;
+ args.WeightlessFrictionNoInput = ent.Comp.WeightlessFrictionNoInput;
}
- private void OnJetpackCanWeightlessMove(EntityUid uid, JetpackComponent component, ref CanWeightlessMoveEvent args)
+ private void OnMapInit(EntityUid uid, JetpackComponent component, MapInitEvent args)
{
- args.CanMove = true;
+ _actionContainer.EnsureAction(uid, ref component.ToggleActionEntity, component.ToggleAction);
+ Dirty(uid, component);
}
private void OnJetpackUserGravityChanged(ref GravityChangedEvent ev)
SetEnabled(uid, component, false, args.User);
}
+ private void OnJetpackMoved(Entity<JetpackComponent> ent, ref EntGotInsertedIntoContainerMessage args)
+ {
+ if (args.Container.Owner != ent.Comp.JetpackUser)
+ SetEnabled(ent, ent.Comp, false, ent.Comp.JetpackUser);
+ }
+
private void OnJetpackUserCanWeightless(EntityUid uid, JetpackUserComponent component, ref CanWeightlessMoveEvent args)
{
args.CanMove = true;
}
}
- private void SetupUser(EntityUid user, EntityUid jetpackUid)
+ private void SetupUser(EntityUid user, EntityUid jetpackUid, JetpackComponent component)
{
- var userComp = EnsureComp<JetpackUserComponent>(user);
- _mover.SetRelay(user, jetpackUid);
+ EnsureComp<JetpackUserComponent>(user, out var userComp);
+ component.JetpackUser = user;
if (TryComp<PhysicsComponent>(user, out var physics))
_physics.SetBodyStatus(user, physics, BodyStatus.InAir);
userComp.Jetpack = jetpackUid;
+ userComp.WeightlessAcceleration = component.Acceleration;
+ userComp.WeightlessModifier = component.WeightlessModifier;
+ userComp.WeightlessFriction = component.Friction;
+ userComp.WeightlessFrictionNoInput = component.Friction;
+ _movementSpeedModifier.RefreshWeightlessModifiers(user);
}
- private void RemoveUser(EntityUid uid)
+ private void RemoveUser(EntityUid uid, JetpackComponent component)
{
if (!RemComp<JetpackUserComponent>(uid))
return;
+ component.JetpackUser = null;
+
if (TryComp<PhysicsComponent>(uid, out var physics))
_physics.SetBodyStatus(uid, physics, BodyStatus.OnGround);
- RemComp<RelayInputMoverComponent>(uid);
+ _movementSpeedModifier.RefreshWeightlessModifiers(uid);
}
private void OnJetpackToggle(EntityUid uid, JetpackComponent component, ToggleJetpackEvent args)
{
if (IsEnabled(uid) == enabled ||
enabled && !CanEnable(uid, component))
- {
return;
+
+ if (user == null)
+ {
+ if (!Container.TryGetContainingContainer((uid, null, null), out var container))
+ return;
+ user = container.Owner;
}
if (enabled)
{
+ SetupUser(user.Value, uid, component);
EnsureComp<ActiveJetpackComponent>(uid);
}
else
{
+ RemoveUser(user.Value, component);
RemComp<ActiveJetpackComponent>(uid);
}
- if (user == null)
- {
- Container.TryGetContainingContainer((uid, null, null), out var container);
- user = container?.Owner;
- }
-
- // Can't activate if no one's using.
- if (user == null && enabled)
- return;
-
- if (user != null)
- {
- if (enabled)
- {
- SetupUser(user.Value, uid);
- }
- else
- {
- RemoveUser(user.Value);
- }
-
- _movementSpeedModifier.RefreshMovementSpeedModifiers(user.Value);
- }
Appearance.SetData(uid, JetpackVisuals.Enabled, enabled);
Dirty(uid, component);
}
// If we updated parent then cancel the accumulator and force it now.
- if (!TryUpdateRelative(mover, XformQuery.GetComponent(uid)) && mover.TargetRelativeRotation.Equals(Angle.Zero))
+ if (!TryUpdateRelative(uid, mover, XformQuery.GetComponent(uid)) && mover.TargetRelativeRotation.Equals(Angle.Zero))
return;
mover.LerpTarget = TimeSpan.Zero;
Dirty(uid, mover);
}
- private bool TryUpdateRelative(InputMoverComponent mover, TransformComponent xform)
+ private bool TryUpdateRelative(EntityUid uid, InputMoverComponent mover, TransformComponent xform)
{
var relative = xform.GridUid;
relative ??= xform.MapUid;
// Okay need to get our old relative rotation with respect to our new relative rotation
// e.g. if we were right side up on our current grid need to get what that is on our new grid.
- var currentRotation = Angle.Zero;
- var targetRotation = Angle.Zero;
+ var oldRelativeRot = Angle.Zero;
+ var relativeRot = Angle.Zero;
// Get our current relative rotation
if (XformQuery.TryGetComponent(mover.RelativeEntity, out var oldRelativeXform))
{
- currentRotation = _transform.GetWorldRotation(oldRelativeXform, XformQuery) + mover.RelativeRotation;
+ oldRelativeRot = _transform.GetWorldRotation(oldRelativeXform);
}
if (XformQuery.TryGetComponent(relative, out var relativeXform))
{
// This is our current rotation relative to our new parent.
- mover.RelativeRotation = (currentRotation - _transform.GetWorldRotation(relativeXform)).FlipPositive();
+ relativeRot = _transform.GetWorldRotation(relativeXform);
}
- // If we went from grid -> map we'll preserve our worldrotation
- if (relative != null && HasComp<MapComponent>(relative.Value))
+ var diff = relativeRot - oldRelativeRot;
+
+ // If we're going from a grid -> map then preserve the relative rotation so it's seamless if they go into space and back.
+ if (HasComp<MapComponent>(relative) && HasComp<MapGridComponent>(mover.RelativeEntity))
{
- targetRotation = currentRotation.FlipPositive().Reduced();
+ mover.TargetRelativeRotation -= diff;
}
- // If we went from grid -> grid OR grid -> map then snap the target to cardinal and lerp there.
- // OR just rotate to zero (depending on cvar)
- else if (relative != null && MapGridQuery.HasComp(relative.Value))
+ // Snap to nearest cardinal if map -> grid
+ else if (HasComp<MapGridComponent>(relative) && HasComp<MapComponent>(mover.RelativeEntity))
{
- if (CameraRotationLocked)
- targetRotation = Angle.Zero;
- else
- targetRotation = mover.RelativeRotation.GetCardinalDir().ToAngle().Reduced();
+ var targetDir = mover.TargetRelativeRotation - diff;
+ targetDir = targetDir.GetCardinalDir().ToAngle().Reduced();
+ mover.TargetRelativeRotation = targetDir;
}
+ // Preserve target rotation in relation to the new parent.
+ // Regardless of what the target is don't want the eye to move at all (from the player's perspective).
+ mover.RelativeRotation -= diff;
+
mover.RelativeEntity = relative;
- mover.TargetRelativeRotation = targetRotation;
+ Dirty(uid, mover);
return true;
}
// Relayed movement just uses the same keybinds given we're moving the relayed entity
// the same as us.
+ // TODO: Should move this into HandleMobMovement itself.
if (TryComp<RelayInputMoverComponent>(entity, out var relayMover))
{
DebugTools.Assert(relayMover.RelayEntity != entity);
using System.Diagnostics.CodeAnalysis;
+using System.Net;
using System.Numerics;
using Content.Shared.Bed.Sleep;
using Content.Shared.CCVar;
using Robust.Shared.Physics.Controllers;
using Robust.Shared.Physics.Systems;
using Robust.Shared.Prototypes;
+using Robust.Shared.Serialization.Manager.Exceptions;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
using PullableComponent = Content.Shared.Movement.Pulling.Components.PullableComponent;
private static readonly ProtoId<TagPrototype> FootstepSoundTag = "FootstepSound";
- /// <summary>
- /// <see cref="CCVars.StopSpeed"/>
- /// </summary>
- private float _stopSpeed;
-
private bool _relativeMovement;
+ private float _minDamping;
+ private float _airDamping;
+ private float _offGridDamping;
/// <summary>
/// Cache the mob movement calculation to re-use elsewhere.
FootstepModifierQuery = GetEntityQuery<FootstepModifierComponent>();
MapGridQuery = GetEntityQuery<MapGridComponent>();
+ SubscribeLocalEvent<MovementSpeedModifierComponent, TileFrictionEvent>(OnTileFriction);
+
InitializeInput();
InitializeRelay();
Subs.CVar(_configManager, CCVars.RelativeMovement, value => _relativeMovement = value, true);
- Subs.CVar(_configManager, CCVars.StopSpeed, value => _stopSpeed = value, true);
+ Subs.CVar(_configManager, CCVars.MinFriction, value => _minDamping = value, true);
+ Subs.CVar(_configManager, CCVars.AirFriction, value => _airDamping = value, true);
+ Subs.CVar(_configManager, CCVars.OffgridFriction, value => _offGridDamping = value, true);
UpdatesBefore.Add(typeof(TileFrictionController));
}
/// Movement while considering actionblockers, weightlessness, etc.
/// </summary>
protected void HandleMobMovement(
- EntityUid uid,
- InputMoverComponent mover,
- EntityUid physicsUid,
- PhysicsComponent physicsComponent,
- TransformComponent xform,
+ Entity<InputMoverComponent> entity,
float frameTime)
{
- var canMove = mover.CanMove;
- if (RelayTargetQuery.TryGetComponent(uid, out var relayTarget))
+ var uid = entity.Owner;
+ var mover = entity.Comp;
+
+ // If we're a relay then apply all of our data to the parent instead and go next.
+ if (RelayQuery.TryComp(uid, out var relay))
{
- if (_mobState.IsIncapacitated(relayTarget.Source) ||
- TryComp<SleepingComponent>(relayTarget.Source, out _) ||
- !MoverQuery.TryGetComponent(relayTarget.Source, out var relayedMover))
+ if (!MoverQuery.TryComp(relay.RelayEntity, out var relayTargetMover))
+ return;
+
+ // Always lerp rotation so relay entities aren't cooked.
+ LerpRotation(uid, mover, frameTime);
+ var dirtied = false;
+
+ if (relayTargetMover.RelativeEntity != mover.RelativeEntity)
{
- canMove = false;
+ relayTargetMover.RelativeEntity = mover.RelativeEntity;
+ dirtied = true;
}
- else
+
+ if (relayTargetMover.RelativeRotation != mover.RelativeRotation)
+ {
+ relayTargetMover.RelativeRotation = mover.RelativeRotation;
+ dirtied = true;
+ }
+
+ if (relayTargetMover.TargetRelativeRotation != mover.TargetRelativeRotation)
{
- mover.RelativeEntity = relayedMover.RelativeEntity;
- mover.RelativeRotation = relayedMover.RelativeRotation;
- mover.TargetRelativeRotation = relayedMover.TargetRelativeRotation;
+ relayTargetMover.TargetRelativeRotation = mover.TargetRelativeRotation;
+ dirtied = true;
}
+
+ if (relayTargetMover.CanMove != mover.CanMove)
+ {
+ relayTargetMover.CanMove = mover.CanMove;
+ dirtied = true;
+ }
+
+ if (dirtied)
+ {
+ Dirty(relay.RelayEntity, relayTargetMover);
+ }
+
+ return;
}
- // Update relative movement
- if (mover.LerpTarget < Timing.CurTime)
+ if (!XformQuery.TryComp(entity.Owner, out var xform))
+ return;
+
+ RelayTargetQuery.TryComp(uid, out var relayTarget);
+ var relaySource = relayTarget?.Source;
+
+ // If we're not the target of a relay then handle lerp data.
+ if (relaySource == null)
{
- if (TryUpdateRelative(mover, xform))
+ // Update relative movement
+ if (mover.LerpTarget < Timing.CurTime)
{
- Dirty(uid, mover);
+ TryUpdateRelative(uid, mover, xform);
}
- }
- LerpRotation(uid, mover, frameTime);
+ LerpRotation(uid, mover, frameTime);
+ }
- if (!canMove
- || physicsComponent.BodyStatus != BodyStatus.OnGround && !CanMoveInAirQuery.HasComponent(uid)
+ // If we can't move then just use tile-friction / no movement handling.
+ if (!mover.CanMove
+ || !PhysicsQuery.TryComp(uid, out var physicsComponent)
|| PullableQuery.TryGetComponent(uid, out var pullable) && pullable.BeingPulled)
{
UsedMobMovement[uid] = false;
return;
}
- UsedMobMovement[uid] = true;
- // Specifically don't use mover.Owner because that may be different to the actual physics body being moved.
- var weightless = _gravity.IsWeightless(physicsUid, physicsComponent, xform);
- var (walkDir, sprintDir) = GetVelocityInput(mover);
- var touching = false;
+ // If the body is in air but isn't weightless then it can't move
+ // TODO: MAKE ISWEIGHTLESS EVENT BASED
+ var weightless = _gravity.IsWeightless(uid, physicsComponent, xform);
+ var inAirHelpless = false;
- // Handle wall-pushes.
- if (weightless)
+ if (physicsComponent.BodyStatus != BodyStatus.OnGround && !CanMoveInAirQuery.HasComponent(uid))
{
- if (xform.GridUid != null)
- touching = true;
-
- if (!touching)
+ if (!weightless)
{
- var ev = new CanWeightlessMoveEvent(uid);
- RaiseLocalEvent(uid, ref ev, true);
- // No gravity: is our entity touching anything?
- touching = ev.CanMove;
-
- if (!touching && TryComp<MobMoverComponent>(uid, out var mobMover))
- touching |= IsAroundCollider(PhysicsSystem, xform, mobMover, physicsUid, physicsComponent);
+ UsedMobMovement[uid] = false;
+ return;
}
+ inAirHelpless = true;
}
+ UsedMobMovement[uid] = true;
+
+ var moveSpeedComponent = ModifierQuery.CompOrNull(uid);
+
+ float friction;
+ float accel;
+ Vector2 wishDir;
+ var velocity = physicsComponent.LinearVelocity;
+
// Get current tile def for things like speed/friction mods
ContentTileDefinition? tileDef = null;
- // Don't bother getting the tiledef here if we're weightless or in-air
- // since no tile-based modifiers should be applying in that situation
- if (MapGridQuery.TryComp(xform.GridUid, out var gridComp)
- && _mapSystem.TryGetTileRef(xform.GridUid.Value, gridComp, xform.Coordinates, out var tile)
- && !(weightless || physicsComponent.BodyStatus == BodyStatus.InAir))
+ var touching = false;
+ // Whether we use tilefriction or not
+ if (weightless || inAirHelpless)
{
- tileDef = (ContentTileDefinition) _tileDefinitionManager[tile.Tile.TypeId];
- }
+ // Find the speed we should be moving at and make sure we're not trying to move faster than that
+ var walkSpeed = moveSpeedComponent?.WeightlessWalkSpeed ?? MovementSpeedModifierComponent.DefaultBaseWalkSpeed;
+ var sprintSpeed = moveSpeedComponent?.WeightlessSprintSpeed ?? MovementSpeedModifierComponent.DefaultBaseSprintSpeed;
- // Regular movement.
- // Target velocity.
- // This is relative to the map / grid we're on.
- var moveSpeedComponent = ModifierQuery.CompOrNull(uid);
-
- var walkSpeed = moveSpeedComponent?.CurrentWalkSpeed ?? MovementSpeedModifierComponent.DefaultBaseWalkSpeed;
- var sprintSpeed = moveSpeedComponent?.CurrentSprintSpeed ?? MovementSpeedModifierComponent.DefaultBaseSprintSpeed;
+ wishDir = AssertValidWish(mover, walkSpeed, sprintSpeed);
- var total = walkDir * walkSpeed + sprintDir * sprintSpeed;
+ var ev = new CanWeightlessMoveEvent(uid);
+ RaiseLocalEvent(uid, ref ev, true);
- var parentRotation = GetParentGridAngle(mover);
- var wishDir = _relativeMovement ? parentRotation.RotateVec(total) : total;
+ touching = ev.CanMove || xform.GridUid != null || MapGridQuery.HasComp(xform.GridUid);
- DebugTools.Assert(MathHelper.CloseToPercent(total.Length(), wishDir.Length()));
+ // If we're not on a grid, and not able to move in space check if we're close enough to a grid to touch.
+ if (!touching && MobMoverQuery.TryComp(uid, out var mobMover))
+ touching |= IsAroundCollider(PhysicsSystem, xform, mobMover, uid, physicsComponent);
- float friction;
- float weightlessModifier;
- float accel;
- var velocity = physicsComponent.LinearVelocity;
-
- // Whether we use weightless friction or not.
- if (weightless)
- {
- if (gridComp == null && !MapGridQuery.HasComp(xform.GridUid))
- friction = moveSpeedComponent?.OffGridFriction ?? MovementSpeedModifierComponent.DefaultOffGridFriction;
- else if (wishDir != Vector2.Zero && touching)
- friction = moveSpeedComponent?.WeightlessFriction ?? MovementSpeedModifierComponent.DefaultWeightlessFriction;
+ // If we're touching then use the weightless values
+ if (touching)
+ {
+ touching = true;
+ if (wishDir != Vector2.Zero)
+ friction = moveSpeedComponent?.WeightlessFriction ?? _airDamping;
+ else
+ friction = moveSpeedComponent?.WeightlessFrictionNoInput ?? _airDamping;
+ }
+ // Otherwise use the off-grid values.
else
- friction = moveSpeedComponent?.WeightlessFrictionNoInput ?? MovementSpeedModifierComponent.DefaultWeightlessFrictionNoInput;
+ {
+ friction = moveSpeedComponent?.OffGridFriction ?? _offGridDamping;
+ }
- weightlessModifier = moveSpeedComponent?.WeightlessModifier ?? MovementSpeedModifierComponent.DefaultWeightlessModifier;
accel = moveSpeedComponent?.WeightlessAcceleration ?? MovementSpeedModifierComponent.DefaultWeightlessAcceleration;
}
else
{
- if (wishDir != Vector2.Zero || moveSpeedComponent?.FrictionNoInput == null)
+ if (MapGridQuery.TryComp(xform.GridUid, out var gridComp)
+ && _mapSystem.TryGetTileRef(xform.GridUid.Value, gridComp, xform.Coordinates, out var tile))
+ tileDef = (ContentTileDefinition) _tileDefinitionManager[tile.Tile.TypeId];
+
+ var walkSpeed = moveSpeedComponent?.CurrentWalkSpeed ?? MovementSpeedModifierComponent.DefaultBaseWalkSpeed;
+ var sprintSpeed = moveSpeedComponent?.CurrentSprintSpeed ?? MovementSpeedModifierComponent.DefaultBaseSprintSpeed;
+
+ wishDir = AssertValidWish(mover, walkSpeed, sprintSpeed);
+
+ if (wishDir != Vector2.Zero)
{
- friction = tileDef?.MobFriction ?? moveSpeedComponent?.Friction ?? MovementSpeedModifierComponent.DefaultFriction;
+ friction = moveSpeedComponent?.Friction ?? MovementSpeedModifierComponent.DefaultFriction;
+ friction *= tileDef?.MobFriction ?? tileDef?.Friction ?? 1f;
}
else
{
- friction = tileDef?.MobFrictionNoInput ?? moveSpeedComponent.FrictionNoInput ?? MovementSpeedModifierComponent.DefaultFrictionNoInput;
+ friction = moveSpeedComponent?.FrictionNoInput ?? MovementSpeedModifierComponent.DefaultFrictionNoInput;
+ friction *= tileDef?.Friction ?? 1f;
}
- weightlessModifier = 1f;
- accel = tileDef?.MobAcceleration ?? moveSpeedComponent?.Acceleration ?? MovementSpeedModifierComponent.DefaultAcceleration;
+ accel = moveSpeedComponent?.Acceleration ?? MovementSpeedModifierComponent.DefaultAcceleration;
+ accel *= tileDef?.MobAcceleration ?? 1f;
}
+ // This way friction never exceeds acceleration when you're trying to move.
+ // If you want to slow down an entity with "friction" you shouldn't be using this system.
+ if (wishDir != Vector2.Zero)
+ friction = Math.Min(friction, accel);
+ friction = Math.Max(friction, _minDamping);
var minimumFrictionSpeed = moveSpeedComponent?.MinimumFrictionSpeed ?? MovementSpeedModifierComponent.DefaultMinimumFrictionSpeed;
Friction(minimumFrictionSpeed, frameTime, friction, ref velocity);
- wishDir *= weightlessModifier;
-
if (!weightless || touching)
Accelerate(ref velocity, in wishDir, accel, frameTime);
SetWishDir((uid, mover), wishDir);
- PhysicsSystem.SetLinearVelocity(physicsUid, velocity, body: physicsComponent);
+ /*
+ * SNAKING!!! >-( 0 ================>
+ * Snaking is a feature where you can move faster by strafing in a direction perpendicular to the
+ * direction you intend to move while still holding the movement key for the direction you're trying to move.
+ * Snaking only works if acceleration exceeds friction, and it's effectiveness scales as acceleration continues
+ * to exceed friction.
+ * Snaking works because friction is applied first in the direction of our current velocity, while acceleration
+ * is applied after in our "Wish Direction" and is capped by the dot of our wish direction and current direction.
+ * This means when you change direction, you're technically able to accelerate more than what the velocity cap
+ * allows, but friction normally eats up the extra movement you gain.
+ * By strafing as stated above you can increase your speed by about 1.4 (square root of 2).
+ * This only works if friction is low enough so be sure that anytime you are letting a mob move in a low friction
+ * environment you take into account the fact they can snake! Also be sure to lower acceleration as well to
+ * prevent jerky movement!
+ */
+ PhysicsSystem.SetLinearVelocity(uid, velocity, body: physicsComponent);
// Ensures that players do not spiiiiiiin
- PhysicsSystem.SetAngularVelocity(physicsUid, 0, body: physicsComponent);
+ PhysicsSystem.SetAngularVelocity(uid, 0, body: physicsComponent);
// Handle footsteps at the end
- if (total != Vector2.Zero)
+ if (wishDir != Vector2.Zero)
{
if (!NoRotateQuery.HasComponent(uid))
{
// TODO apparently this results in a duplicate move event because "This should have its event run during
// island solver"??. So maybe SetRotation needs an argument to avoid raising an event?
var worldRot = _transform.GetWorldRotation(xform);
- _transform.SetLocalRotation(xform, xform.LocalRotation + wishDir.ToWorldAngle() - worldRot);
+
+ _transform.SetLocalRotation(uid, xform.LocalRotation + wishDir.ToWorldAngle() - worldRot, xform);
}
if (!weightless && MobMoverQuery.TryGetComponent(uid, out var mobMover) &&
.WithVariation(sound.Params.Variation ?? mobMover.FootstepVariation);
// If we're a relay target then predict the sound for all relays.
- if (relayTarget != null)
+ if (relaySource != null)
{
- _audio.PlayPredicted(sound, uid, relayTarget.Source, audioParams);
+ _audio.PlayPredicted(sound, uid, relaySource.Value, audioParams);
}
else
{
adjustment = Math.Clamp(adjustment, -angleDiff, angleDiff);
}
- mover.RelativeRotation += adjustment;
- mover.RelativeRotation.FlipPositive();
+ mover.RelativeRotation = (mover.RelativeRotation + adjustment).FlipPositive();
Dirty(uid, mover);
}
else if (!angleDiff.Equals(Angle.Zero))
{
- mover.TargetRelativeRotation.FlipPositive();
- mover.RelativeRotation = mover.TargetRelativeRotation;
+ mover.RelativeRotation = mover.TargetRelativeRotation.FlipPositive();
Dirty(uid, mover);
}
}
if (speed < minimumFrictionSpeed)
return;
- var drop = 0f;
+ // This equation is lifted from the Physics Island solver.
+ // We re-use it here because Kinematic Controllers can't/shouldn't use the Physics Friction
+ velocity *= Math.Clamp(1.0f - frameTime * friction, 0.0f, 1.0f);
- var control = MathF.Max(_stopSpeed, speed);
- drop += control * friction * frameTime;
-
- var newSpeed = MathF.Max(0f, speed - drop);
-
- if (newSpeed.Equals(speed))
- return;
-
- newSpeed /= speed;
- velocity *= newSpeed;
}
/// <summary>
sound = haveShoes ? tileDef.FootstepSounds : tileDef.BarestepSounds;
return sound != null;
}
+
+ private Vector2 AssertValidWish(InputMoverComponent mover, float walkSpeed, float sprintSpeed)
+ {
+ var (walkDir, sprintDir) = GetVelocityInput(mover);
+
+ var total = walkDir * walkSpeed + sprintDir * sprintSpeed;
+
+ var parentRotation = GetParentGridAngle(mover);
+ var wishDir = _relativeMovement ? parentRotation.RotateVec(total) : total;
+
+ DebugTools.Assert(MathHelper.CloseToPercent(total.Length(), wishDir.Length()));
+
+ return wishDir;
+ }
+
+ private void OnTileFriction(Entity<MovementSpeedModifierComponent> ent, ref TileFrictionEvent args)
+ {
+ if (!TryComp<PhysicsComponent>(ent, out var physicsComponent) || !XformQuery.TryComp(ent, out var xform))
+ return;
+
+ // TODO: Make IsWeightless event based!!!
+ if (physicsComponent.BodyStatus != BodyStatus.OnGround || _gravity.IsWeightless(ent, physicsComponent, xform))
+ args.Modifier *= ent.Comp.BaseWeightlessFriction;
+ else
+ args.Modifier *= ent.Comp.BaseFriction;
+ }
}
-using Content.Shared.Inventory;
using Content.Shared.Movement.Components;
using Content.Shared.Movement.Events;
using Content.Shared.Gravity;
// TODO full-game-save
// Either these need to be processed before a map is saved, or slowed/slowing entities need to update on init.
- private HashSet<EntityUid> _toUpdate = new();
- private HashSet<EntityUid> _toRemove = new();
+ private readonly HashSet<EntityUid> _toUpdate = new();
+ private readonly HashSet<EntityUid> _toRemove = new();
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SpeedModifierContactsComponent, StartCollideEvent>(OnEntityEnter);
SubscribeLocalEvent<SpeedModifierContactsComponent, EndCollideEvent>(OnEntityExit);
- SubscribeLocalEvent<SpeedModifiedByContactComponent, RefreshMovementSpeedModifiersEvent>(MovementSpeedCheck);
+ SubscribeLocalEvent<SpeedModifiedByContactComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshMovementSpeedModifiers);
SubscribeLocalEvent<SpeedModifierContactsComponent, ComponentShutdown>(OnShutdown);
UpdatesAfter.Add(typeof(SharedPhysicsSystem));
_toUpdate.Clear();
}
- public void ChangeModifiers(EntityUid uid, float speed, SpeedModifierContactsComponent? component = null)
+ public void ChangeSpeedModifiers(EntityUid uid, float speed, SpeedModifierContactsComponent? component = null)
{
- ChangeModifiers(uid, speed, speed, component);
+ ChangeSpeedModifiers(uid, speed, speed, component);
}
- public void ChangeModifiers(EntityUid uid, float walkSpeed, float sprintSpeed, SpeedModifierContactsComponent? component = null)
+ public void ChangeSpeedModifiers(EntityUid uid, float walkSpeed, float sprintSpeed, SpeedModifierContactsComponent? component = null)
{
if (!Resolve(uid, ref component))
- {
return;
- }
+
component.WalkSpeedModifier = walkSpeed;
component.SprintSpeedModifier = sprintSpeed;
Dirty(uid, component);
_toUpdate.UnionWith(_physics.GetContactingEntities(uid, phys));
}
- private void MovementSpeedCheck(EntityUid uid, SpeedModifiedByContactComponent component, RefreshMovementSpeedModifiersEvent args)
+ private void OnRefreshMovementSpeedModifiers(EntityUid uid, SpeedModifiedByContactComponent component, RefreshMovementSpeedModifiersEvent args)
{
if (!EntityManager.TryGetComponent<PhysicsComponent>(uid, out var physicsComponent))
return;
}
// SpeedModifierContactsComponent takes priority over SlowedOverSlipperyComponent, effectively overriding the slippery slow.
- if (TryComp<SlipperyComponent>(ent, out var slipperyComponent) && speedModified == false)
+ if (HasComp<SlipperyComponent>(ent) && speedModified == false)
{
var evSlippery = new GetSlowedOverSlipperyModifierEvent();
RaiseLocalEvent(uid, ref evSlippery);
- if (evSlippery.SlowdownModifier != 1)
+ if (MathHelper.CloseTo(evSlippery.SlowdownModifier, 1))
{
walkSpeed += evSlippery.SlowdownModifier;
sprintSpeed += evSlippery.SlowdownModifier;
}
}
- if (entries > 0)
+ if (entries > 0 && (!MathHelper.CloseTo(walkSpeed, entries) || !MathHelper.CloseTo(sprintSpeed, entries)))
{
walkSpeed /= entries;
sprintSpeed /= entries;
{
var sliding = EnsureComp<SlidingComponent>(other);
sliding.CollidingEntities.Add(uid);
+ // Why the fuck does this assertion stack overflow every once in a while
DebugTools.Assert(_physics.GetContactingEntities(other, physics).Contains(uid));
}
}
/// Friction modifier for knocked down players.
/// Doesn't make them faster but makes them slow down... slower.
/// </summary>
- public const float KnockDownModifier = 0.4f;
+ public const float KnockDownModifier = 0.2f;
public override void Initialize()
{
public const float FlyTimePercentage = 0.8f;
+ private const float TileFrictionMod = 1.5f;
+
private float _frictionModifier;
+ private float _airDamping;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly SharedGravitySystem _gravity = default!;
base.Initialize();
Subs.CVar(_configManager, CCVars.TileFrictionModifier, value => _frictionModifier = value, true);
+ Subs.CVar(_configManager, CCVars.AirFriction, value => _airDamping = value, true);
}
public void TryThrow(
};
// if not given, get the default friction value for distance calculation
- var tileFriction = friction ?? _frictionModifier * TileFrictionController.DefaultFriction;
+ var tileFriction = friction ?? _frictionModifier * TileFrictionMod;
if (tileFriction == 0f)
compensateFriction = false; // cannot calculate this if there is no friction
// else let the item land on the cursor and from where it slides a little further.
// This is an exact formula we get from exponentially decaying velocity after landing.
// If someone changes how tile friction works at some point, this will have to be adjusted.
+ // This doesn't actually compensate for air friction, but it's low enough it shouldn't matter.
var throwSpeed = compensateFriction ? direction.Length() / (flyTime + 1 / tileFriction) : baseThrowSpeed;
var impulseVector = direction.Normalized() * throwSpeed * physics.Mass;
_physics.ApplyLinearImpulse(uid, impulseVector, body: physics);
components:
- type: Clickable
- type: Slippery
- - type: TileFrictionModifier
- modifier: 0.3
- type: Transform
noRot: true
anchored: true
baseSprintSpeed : 4
weightlessAcceleration: 1.5
weightlessFriction: 1
- weightlessModifier: 1
+ baseWeightlessModifier: 1
- type: Damageable
damageContainer: Biological
damageModifierSet: Moth
- type: MovementSpeedModifier
baseWalkSpeed: 3
baseSprintSpeed: 5
- weightlessModifier: 1.5
+ baseWeightlessModifier: 1.5
- type: Sprite
sprite: Mobs/Demons/behonker.rsi
layers:
- type: NoSlip
- type: MovementAlwaysTouching
- type: CanMoveInAir
+ - type: MovementSpeedModifier
- type: MovementSpeedModifier
baseWalkSpeed: 3
baseSprintSpeed: 5
- weightlessModifier: 1.5
+ baseWeightlessModifier: 1.5
- type: RandomSprite
available:
- enum.DamageStateVisualLayers.Base:
- type: MovementSpeedModifier
weightlessAcceleration: 1.5 # Move around more easily in space.
weightlessFriction: 1
- weightlessModifier: 1
+ baseWeightlessModifier: 1
- type: Flammable
damage:
types:
state: "creampie_moth"
visible: false
- type: Inventory
- speciesId: moth
+ speciesId: moth
femaleDisplacements:
jumpsuit:
sizeMaps:
- type: HumanoidAppearance
species: Moth
- type: Inventory
- speciesId: moth
+ speciesId: moth
femaleDisplacements:
jumpsuit:
sizeMaps:
- type: Physics
bodyType: Dynamic
linearDamping: 0
+ - type: TileFrictionModifier
+ modifier: 0
- type: PointLight
radius: 3
color: red
gravityState: true
- type: InputMover
- type: MovementSpeedModifier
- weightlessAcceleration: 5
- weightlessModifier: 2
- weightlessFriction: 0
- friction: 0
- frictionNoInput: 0
+ baseWeightlessAcceleration: 5
+ baseWeightlessModifier: 2
+ baseWeightlessFriction: 0
+ baseFriction: 0
+ offGridFriction: 0
- type: CanMoveInAir
- type: MovementAlwaysTouching
- type: NoSlip
coldDamage: {}
coldDamageThreshold: 0
- type: FrictionContacts
+ - type: TileFrictionModifier
+ modifier: 0.05
name: jetpack
description: It's a jetpack. It can hold 5 L of gas.
components:
- - type: InputMover
- toParent: true
- - type: MovementSpeedModifier
- weightlessAcceleration: 1
- weightlessFriction: 0.3
- weightlessModifier: 1.2
- - type: CanMoveInAir
- type: Sprite
sprite: Objects/Tanks/Jetpacks/blue.rsi
state: icon
collection: FootstepCarpet
barestepSounds:
collection: BarestepCarpet
- friction: 0.25
+ friction: 1.25
itemDrop: FloorTileItemArcadeBlue
heatCapacity: 10000
collection: FootstepCarpet
barestepSounds:
collection: BarestepCarpet
- friction: 0.25
+ friction: 1.25
itemDrop: FloorTileItemArcadeBlue2
heatCapacity: 10000
collection: FootstepCarpet
barestepSounds:
collection: BarestepCarpet
- friction: 0.25
+ friction: 1.25
itemDrop: FloorTileItemArcadeRed
heatCapacity: 10000
collection: FootstepCarpet
barestepSounds:
collection: BarestepCarpet
- friction: 0.25
+ friction: 1.25
itemDrop: FloorTileItemEighties
heatCapacity: 10000
collection: FootstepCarpet
barestepSounds:
collection: BarestepCarpet
- friction: 0.25
+ friction: 1.25
itemDrop: FloorTileItemCarpetClown
heatCapacity: 10000
collection: FootstepCarpet
barestepSounds:
collection: BarestepCarpet
- friction: 0.25
+ friction: 1.25
itemDrop: FloorTileItemCarpetOffice
heatCapacity: 10000
deconstructTools: [ Prying ]
footstepSounds:
collection: FootstepFloor
- friction: 0.25
+ friction: 1.25
itemDrop: FloorTileItemBoxing
heatCapacity: 10000
deconstructTools: [ Prying ]
footstepSounds:
collection: FootstepFloor
- friction: 0.25
+ friction: 1.25
itemDrop: FloorTileItemGym
heatCapacity: 10000
footstepSounds:
collection: FootstepBlood
itemDrop: FloorTileItemFlesh
- friction: 0.05 #slippy
+ friction: 0.25 #slippy
heatCapacity: 10000
- type: tile
deconstructTools: [ Prying ]
friction: 0.05
heatCapacity: 10000
- mobFriction: 0.5
- mobFrictionNoInput: 0.05
- mobAcceleration: 2
+ mobFriction: 0.05
+ mobAcceleration: 0.1
itemDrop: FloorTileItemAstroIce
- type: tile
friction: 0.05
heatCapacity: 10000
weather: true
- mobFriction: 0.5
- mobFrictionNoInput: 0.05
- mobAcceleration: 2
+ mobAcceleration: 0.1
indestructible: true
# Dug snow
isSubfloor: true
footstepSounds:
collection: FootstepPlating
- friction: 0.3
+ friction: 1.5
heatCapacity: 10000
- type: tile
isSubfloor: true
footstepSounds:
collection: FootstepPlating
- friction: 0.3
+ friction: 1.5
heatCapacity: 10000
- type: tile
isSubfloor: true
footstepSounds:
collection: FootstepPlating
- friction: 0.3
+ friction: 1.5
heatCapacity: 10000
- type: tile
isSubfloor: true
footstepSounds:
collection: FootstepPlating
- friction: 0.3
+ friction: 1.5
heatCapacity: 10000
- type: tile
isSubfloor: true
footstepSounds:
collection: FootstepPlating
- friction: 0.15 #a little less then actual snow
+ friction: 0.75 #a little less then actual snow
heatCapacity: 10000
- type: tile
weather: true
footstepSounds:
collection: FootstepCatwalk
- friction: 0.3
+ friction: 1.5
isSpace: true
itemDrop: PartRodMetal1
heatCapacity: 10000
weather: true
footstepSounds:
collection: FootstepPlating
- friction: 0.3
+ friction: 1.5
isSpace: true
itemDrop: PartRodMetal1
heatCapacity: 10000