Merge physics rewrite

This commit is contained in:
Pieter-Jan Briers
2020-05-23 01:23:36 +02:00
parent b6b4482ca0
commit 18ce80a43c
20 changed files with 224 additions and 104 deletions

View 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;
}
}
}