mirror of
https://github.com/celisej567/gm_construct_port.git
synced 2026-09-19 20:11:46 +03:00
Add files via upload
This commit is contained in:
64
code/entities/DirectionalGravity.cs
Normal file
64
code/entities/DirectionalGravity.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using Sandbox;
|
||||
using System.Linq;
|
||||
|
||||
[Library( "directional_gravity", Title = "Directional Gravity", Spawnable = true )]
|
||||
public partial class DirectionalGravity : Prop
|
||||
{
|
||||
bool enabled = false;
|
||||
|
||||
public override void Spawn()
|
||||
{
|
||||
base.Spawn();
|
||||
|
||||
DeleteOthers();
|
||||
|
||||
SetModel( "models/arrow.vmdl" );
|
||||
SetupPhysicsFromModel( PhysicsMotionType.Dynamic, false );
|
||||
|
||||
enabled = true;
|
||||
}
|
||||
|
||||
private void DeleteOthers()
|
||||
{
|
||||
// Only allow one of these to be spawned at a time
|
||||
foreach ( var ent in All.OfType<DirectionalGravity>()
|
||||
.Where( x => x.IsValid() && x != this ) )
|
||||
{
|
||||
ent.Delete();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
base.OnDestroy();
|
||||
|
||||
if ( IsServer )
|
||||
{
|
||||
PhysicsWorld.UseDefaultGravity();
|
||||
PhysicsWorld.WakeAllBodies();
|
||||
}
|
||||
|
||||
enabled = false;
|
||||
}
|
||||
|
||||
[Event.Physics.PostStep]
|
||||
public void OnPostPhysicsStep()
|
||||
{
|
||||
if ( !IsServer )
|
||||
return;
|
||||
|
||||
if ( !enabled )
|
||||
return;
|
||||
|
||||
if ( !this.IsValid() )
|
||||
return;
|
||||
|
||||
var gravity = Rotation.Down * 800.0f;
|
||||
|
||||
if ( gravity != PhysicsWorld.Gravity )
|
||||
{
|
||||
PhysicsWorld.Gravity = gravity;
|
||||
PhysicsWorld.WakeAllBodies();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user