mirror of
https://github.com/celisej567/gm_construct_port.git
synced 2026-09-27 16:16:14 +03:00
Add files via upload
This commit is contained in:
50
code/entities/ThrusterEntity.cs
Normal file
50
code/entities/ThrusterEntity.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user