private static void UpdatePosition(IPhysBody body, float frameTime) { var ent = body.Entity; if (!body.CanMove() || (body.LinearVelocity.LengthSquared < Epsilon && MathF.Abs(body.AngularVelocity) < Epsilon)) { return; } if (body.LinearVelocity != Vector2.Zero) { var entityMoveMessage = new EntityMovementMessage(); ent.SendMessage(ent.Transform, entityMoveMessage); if (ContainerHelpers.IsInContainer(ent)) { var relayEntityMoveMessage = new RelayMovementEntityMessage(ent); ent.Transform.Parent !.Owner.SendMessage(ent.Transform, relayEntityMoveMessage); // This prevents redundant messages from being sent if solveIterations > 1 and also simulates the entity "colliding" against the locker door when it opens. body.LinearVelocity = Vector2.Zero; } } body.WorldRotation += body.AngularVelocity * frameTime; body.WorldPosition += body.LinearVelocity * frameTime; }
private static void HandleDirChange(ICommonSession?session, Direction dir, ushort subTick, bool state) { if (!TryGetAttachedComponent <IMoverComponent>(session, out var moverComp)) { return; } var owner = session?.AttachedEntity; if (owner != null && session != null) { foreach (var comp in owner.GetAllComponents <IRelayMoveInput>()) { comp.MoveInputPressed(session); } // For stuff like "Moving out of locker" or the likes if (owner.IsInContainer() && (!owner.TryGetComponent(out IMobStateComponent? mobState) || mobState.IsAlive())) { var relayEntityMoveMessage = new RelayMovementEntityMessage(owner); owner.Transform.Parent !.Owner.SendMessage(owner.Transform, relayEntityMoveMessage); } } moverComp.SetVelocityDirection(dir, subTick, state); }
private void UpdatePosition(ICollidableComponent collidable, float frameTime) { var ent = collidable.Entity; if (!collidable.CanMove() || (collidable.LinearVelocity.LengthSquared < Epsilon && MathF.Abs(collidable.AngularVelocity) < Epsilon)) { return; } if (collidable.LinearVelocity != Vector2.Zero) { if (ContainerHelpers.IsInContainer(ent)) { var relayEntityMoveMessage = new RelayMovementEntityMessage(ent); ent.Transform.Parent !.Owner.SendMessage(ent.Transform, relayEntityMoveMessage); // This prevents redundant messages from being sent if solveIterations > 1 and also simulates the entity "colliding" against the locker door when it opens. collidable.LinearVelocity = Vector2.Zero; } } collidable.Owner.Transform.DeferUpdates = true; _deferredUpdates.Add(collidable); collidable.WorldRotation += collidable.AngularVelocity * frameTime; collidable.WorldPosition += collidable.LinearVelocity * frameTime; }
private void UpdatePosition(IPhysicsComponent physics, float frameTime) { var ent = physics.Entity; if (!physics.CanMove() || (physics.LinearVelocity.LengthSquared < Epsilon && MathF.Abs(physics.AngularVelocity) < Epsilon)) { return; } if (physics.LinearVelocity != Vector2.Zero) { if (ContainerHelpers.IsInContainer(ent)) { var relayEntityMoveMessage = new RelayMovementEntityMessage(ent); ent.Transform.Parent !.Owner.SendMessage(ent.Transform, relayEntityMoveMessage); // This prevents redundant messages from being sent if solveIterations > 1 and also simulates the entity "colliding" against the locker door when it opens. physics.LinearVelocity = Vector2.Zero; } } physics.Owner.Transform.DeferUpdates = true; _deferredUpdates.Add(physics); // Slow zone up in here if (physics.LinearVelocity.Length > _speedLimit) { physics.LinearVelocity = physics.LinearVelocity.Normalized * _speedLimit; } physics.WorldRotation += physics.AngularVelocity * frameTime; physics.WorldPosition += physics.LinearVelocity * frameTime; }
private void UpdatePosition(IPhysicsComponent physics, float frameTime) { var ent = physics.Entity; if (!physics.CanMove() || (physics.LinearVelocity.LengthSquared < Epsilon && MathF.Abs(physics.AngularVelocity) < Epsilon)) { return; } if (physics.LinearVelocity != Vector2.Zero) { if (ContainerHelpers.IsInContainer(ent)) { var relayEntityMoveMessage = new RelayMovementEntityMessage(ent); ent.Transform.Parent !.Owner.SendMessage(ent.Transform, relayEntityMoveMessage); // This prevents redundant messages from being sent if solveIterations > 1 and also simulates the entity "colliding" against the locker door when it opens. physics.LinearVelocity = Vector2.Zero; } } physics.Owner.Transform.DeferUpdates = true; _deferredUpdates.Add(physics); // Slow zone up in here if (physics.LinearVelocity.Length > _speedLimit) { physics.LinearVelocity = physics.LinearVelocity.Normalized * _speedLimit; } var newPosition = physics.WorldPosition + physics.LinearVelocity * frameTime; var owner = physics.Owner; var transform = owner.Transform; // Change parent if necessary if (!ContainerHelpers.IsInContainer(owner)) { // This shoouullddnnn'''tt de-parent anything in a container because none of that should have physics applied to it. if (_mapManager.TryFindGridAt(owner.Transform.MapID, newPosition, out var grid) && grid.GridEntityId.IsValid() && grid.GridEntityId != owner.Uid) { if (grid.GridEntityId != transform.ParentUid) { transform.AttachParent(owner.EntityManager.GetEntity(grid.GridEntityId)); } } else { transform.AttachParent(_mapManager.GetMapEntity(transform.MapID)); } } physics.WorldRotation += physics.AngularVelocity * frameTime; physics.WorldPosition = newPosition; }