Add files via upload

This commit is contained in:
celisej567
2021-08-05 17:54:51 +03:00
committed by GitHub
parent d58ad89d11
commit 76b55e2a87
57 changed files with 5632 additions and 0 deletions

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