Merge physics rewrite
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Content.Shared.Physics;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
@@ -48,8 +49,8 @@ namespace Content.Server.GameObjects.EntitySystems
|
||||
if (range > 0f && !(dir.LengthSquared <= range * range)) return false;
|
||||
|
||||
var ray = new CollisionRay(coords.Position, dir.Normalized, collisionMask);
|
||||
var rayResults = _physicsManager.IntersectRayWithPredicate(coords.MapId, ray, dir.Length, predicate, true);
|
||||
if(!rayResults.DidHitObject || (insideBlockerValid && rayResults.DidHitObject && (rayResults.HitPos - otherCoords).Length < 1f))
|
||||
var rayResults = _physicsManager.IntersectRayWithPredicate(coords.MapId, ray, dir.Length, predicate).ToList();
|
||||
if(rayResults.Count == 0 || (insideBlockerValid && rayResults.Count > 0 && (rayResults[0].HitPos - otherCoords).Length < 1f))
|
||||
{
|
||||
|
||||
if (_mapManager.TryFindGridAt(coords, out var mapGrid) && mapGrid != null)
|
||||
|
||||
61
Content.Shared/Physics/MoverController.cs
Normal file
61
Content.Shared/Physics/MoverController.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using Robust.Shared.Interfaces.Physics;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
|
||||
namespace Content.Shared.Physics
|
||||
{
|
||||
public class MoverController: VirtualController
|
||||
{
|
||||
private Vector2 _velocity;
|
||||
private SharedPhysicsComponent _component = null;
|
||||
|
||||
public Vector2 Velocity
|
||||
{
|
||||
get => _velocity;
|
||||
set => _velocity = value;
|
||||
}
|
||||
|
||||
public override SharedPhysicsComponent ControlledComponent
|
||||
{
|
||||
set => _component = value;
|
||||
}
|
||||
|
||||
public MoverController()
|
||||
{
|
||||
_velocity = Vector2.Zero;
|
||||
}
|
||||
|
||||
public void Move(Vector2 velocityDirection, float speed)
|
||||
{
|
||||
if (IoCManager.Resolve<IPhysicsManager>().IsWeightless(_component.Owner.Transform.GridPosition)) return;
|
||||
Push(velocityDirection, speed);
|
||||
}
|
||||
|
||||
public void Push(Vector2 velocityDirection, float speed)
|
||||
{
|
||||
Velocity = velocityDirection * speed;
|
||||
}
|
||||
|
||||
public void StopMoving()
|
||||
{
|
||||
Velocity = Vector2.Zero;
|
||||
}
|
||||
|
||||
public override void UpdateBeforeProcessing()
|
||||
{
|
||||
base.UpdateBeforeProcessing();
|
||||
|
||||
if (Velocity == Vector2.Zero)
|
||||
{
|
||||
// Try to stop movement
|
||||
_component.LinearVelocity = Vector2.Zero;
|
||||
}
|
||||
else
|
||||
{
|
||||
_component.LinearVelocity = Velocity;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
51
Content.Shared/Physics/ThrowController.cs
Normal file
51
Content.Shared/Physics/ThrowController.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using Robust.Shared.Interfaces.Physics;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Timers;
|
||||
|
||||
namespace Content.Shared.Physics
|
||||
{
|
||||
public class ThrowController: VirtualController
|
||||
{
|
||||
private float _throwTime;
|
||||
private SharedPhysicsComponent _component;
|
||||
|
||||
private const float DefaultThrowTime = 0.25f;
|
||||
|
||||
public float ThrowTime
|
||||
{
|
||||
get => _throwTime;
|
||||
set => _throwTime = value;
|
||||
}
|
||||
|
||||
public override SharedPhysicsComponent ControlledComponent
|
||||
{
|
||||
set => _component = value;
|
||||
}
|
||||
|
||||
public void StartThrow(Vector2 initialImpulse)
|
||||
{
|
||||
_component.Momentum = initialImpulse;
|
||||
_component.Status = BodyStatus.InAir;
|
||||
Timer.Spawn((int) (ThrowTime * 1000), StopThrow);
|
||||
}
|
||||
|
||||
public void StopThrow()
|
||||
{
|
||||
if (_component == null) return;
|
||||
if (IoCManager.Resolve<IPhysicsManager>().IsWeightless(_component.Owner.Transform.GridPosition))
|
||||
{
|
||||
Timer.Spawn((int) (ThrowTime * 1000), StopThrow);
|
||||
return;
|
||||
}
|
||||
_component.Status = BodyStatus.OnGround;
|
||||
_component.LinearVelocity = Vector2.Zero;
|
||||
}
|
||||
|
||||
public ThrowController()
|
||||
{
|
||||
ThrowTime = DefaultThrowTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user