mirror of
https://github.com/celisej567/gm_construct_port.git
synced 2026-09-06 20:13:16 +03:00
51 lines
888 B
C#
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();
|
|
}
|
|
}
|
|
}
|