Files
gm_construct_port/code/entities/ThrusterEntity.cs
2021-08-05 17:54:51 +03:00

51 lines
888 B
C#

using Sandbox;
[Library( "ent_thruster" )]
public partial class ThrusterEntity : Prop, IUse
{
public float Force = 1000.0f;
public bool Massless = false;
public PhysicsBody TargetBody;
[Net]
public bool Enabled { get; set; } = true;
[Event.Physics.PostStep]
public virtual void OnPostPhysicsStep()
{
if ( IsServer && Enabled )
{
if ( TargetBody.IsValid() )
{
TargetBody.ApplyForceAt( Position, Rotation.Down * (Massless ? Force * TargetBody.Mass : Force) );
}
else if ( PhysicsBody.IsValid() )
{
PhysicsBody.ApplyForce( Rotation.Down * (Massless ? Force * PhysicsBody.Mass : Force) );
}
}
}
public bool IsUsable( Entity user )
{
return true;
}
public bool OnUse( Entity user )
{
Enabled = !Enabled;
return false;
}
protected override void OnDestroy()
{
base.OnDestroy();
if ( IsClient )
{
KillEffects();
}
}
}