Physics (#3452)
* Content side new physics structure * BroadPhase outline done * But we need to fix WorldAABB * Fix static pvs AABB * Fix import * Rando fixes * B is for balloon * Change human mob hitbox to circle * Decent movement * Start adding friction to player controller I think it's the best way to go about it to keep other objects somewhat consistent for physics. * This baby can fit so many physics bugs in it. * Slight mob mover optimisations. * Player mover kinda works okay. * Beginnings of testbed * More testbed * Circlestack bed * Namespaces * BB fixes * Pull WorldAABB * Joint pulling * Semi-decent movement I guess. * Pulling better * Bullet controller + old movement * im too dumb for this shit * Use kinematic mob controller again It's probably for the best TBH * Stashed shitcode * Remove SlipController * In which movement code is entirely refactored * Singularity fix * Fix ApplyLinearImpulse * MoveRelay fix * Fix door collisions * Disable subfloor collisions Saves on broadphase a fair bit * Re-implement ClimbController * Zumzum's pressure * Laggy item throwing * Minor atmos change * Some caching * Optimise controllers * Optimise CollideWith to hell and back * Re-do throwing and tile friction * Landing too * Optimise controllers * Move CCVars and other stuff swept is beautiful * Cleanup a bunch of controllers * Fix shooting and high pressure movement controller * Flashing improvements * Stuff and things * Combat collisions * Combat mode collisions * Pulling distance joint again * Cleanup physics interfaces * More like scuffedularity * Shit's fucked * Haha tests go green * Bigmoneycrab Co-authored-by: Metal Gear Sloth <metalgearsloth@gmail.com>
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
#nullable enable
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Shared.GameObjects.Components.Items;
|
||||
using Content.Shared.GameObjects.Components.Mobs.State;
|
||||
using Content.Shared.GameObjects.Components.Movement;
|
||||
using Content.Shared.GameObjects.EntitySystems.ActionBlocker;
|
||||
using Content.Shared.Physics;
|
||||
using Content.Shared.Physics.Pull;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Input;
|
||||
using Robust.Shared.Input.Binding;
|
||||
@@ -15,11 +16,11 @@ using Robust.Shared.Players;
|
||||
|
||||
namespace Content.Shared.GameObjects.EntitySystems
|
||||
{
|
||||
public abstract class SharedMoverSystem : EntitySystem
|
||||
/// <summary>
|
||||
/// Handles converting inputs into movement.
|
||||
/// </summary>
|
||||
public sealed class SharedMoverSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
[Dependency] protected readonly IPhysicsManager PhysicsManager = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
@@ -45,109 +46,9 @@ namespace Content.Shared.GameObjects.EntitySystems
|
||||
base.Shutdown();
|
||||
}
|
||||
|
||||
//TODO: reorganize this to make more logical sense
|
||||
protected void UpdateKinematics(ITransformComponent transform, IMoverComponent mover, IPhysicsComponent physics)
|
||||
{
|
||||
physics.EnsureController<MoverController>();
|
||||
|
||||
var weightless = transform.Owner.IsWeightless();
|
||||
|
||||
if (weightless)
|
||||
{
|
||||
// No gravity: is our entity touching anything?
|
||||
var touching = IsAroundCollider(transform, mover, physics);
|
||||
|
||||
if (!touching)
|
||||
{
|
||||
transform.LocalRotation = physics.LinearVelocity.GetDir().ToAngle();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: movement check.
|
||||
var (walkDir, sprintDir) = mover.VelocityDir;
|
||||
var combined = walkDir + sprintDir;
|
||||
if (combined.LengthSquared < 0.001 || !ActionBlockerSystem.CanMove(mover.Owner) && !weightless)
|
||||
{
|
||||
if (physics.TryGetController(out MoverController controller))
|
||||
{
|
||||
controller.StopMoving();
|
||||
}
|
||||
}
|
||||
else if (ActionBlockerSystem.CanMove(mover.Owner))
|
||||
{
|
||||
if (weightless)
|
||||
{
|
||||
if (physics.TryGetController(out MoverController controller))
|
||||
{
|
||||
controller.Push(combined, mover.CurrentPushSpeed);
|
||||
}
|
||||
|
||||
transform.LocalRotation = physics.LinearVelocity.GetDir().ToAngle();
|
||||
return;
|
||||
}
|
||||
|
||||
var total = walkDir * mover.CurrentWalkSpeed + sprintDir * mover.CurrentSprintSpeed;
|
||||
|
||||
{
|
||||
if (physics.TryGetController(out MoverController controller))
|
||||
{
|
||||
controller.Move(total, 1);
|
||||
}
|
||||
}
|
||||
|
||||
transform.LocalRotation = total.GetDir().ToAngle();
|
||||
|
||||
HandleFootsteps(mover);
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void HandleFootsteps(IMoverComponent mover)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private bool IsAroundCollider(ITransformComponent transform, IMoverComponent mover,
|
||||
IPhysicsComponent collider)
|
||||
{
|
||||
foreach (var entity in _entityManager.GetEntitiesInRange(transform.Owner, mover.GrabRange, true))
|
||||
{
|
||||
if (entity == transform.Owner)
|
||||
{
|
||||
continue; // Don't try to push off of yourself!
|
||||
}
|
||||
|
||||
if (!entity.TryGetComponent<IPhysicsComponent>(out var otherCollider) ||
|
||||
!otherCollider.CanCollide ||
|
||||
(collider.CollisionMask & otherCollider.CollisionLayer) == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// Don't count pulled entities
|
||||
if (otherCollider.HasController<PullController>())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// TODO: Item check.
|
||||
var touching = ((collider.CollisionMask & otherCollider.CollisionLayer) != 0x0
|
||||
|| (otherCollider.CollisionMask & collider.CollisionLayer) != 0x0) // Ensure collision
|
||||
&& !entity.HasComponent<IItemComponent>(); // This can't be an item
|
||||
|
||||
if (touching)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private static void HandleDirChange(ICommonSession? session, Direction dir, ushort subTick, bool state)
|
||||
{
|
||||
if (!TryGetAttachedComponent<IMoverComponent>(session, out var moverComp))
|
||||
if (!TryGetAttachedComponent<SharedPlayerInputMoverComponent>(session, out var moverComp))
|
||||
return;
|
||||
|
||||
var owner = session?.AttachedEntity;
|
||||
@@ -158,6 +59,15 @@ namespace Content.Shared.GameObjects.EntitySystems
|
||||
{
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user