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

57
code/tools/LeafBlower.cs Normal file
View File

@@ -0,0 +1,57 @@
namespace Sandbox.Tools
{
[Library( "tool_leafblower", Title = "Leaf Blower", Description = "Blow me", Group = "fun" )]
public partial class LeafBlowerTool : BaseTool
{
protected virtual float Force => 128;
protected virtual float MaxDistance => 512;
protected virtual bool Massless => true;
public override void Simulate()
{
if ( !Host.IsServer )
return;
using ( Prediction.Off() )
{
bool push = Input.Down( InputButton.Attack1 );
if ( !push && !Input.Down( InputButton.Attack2 ) )
return;
var startPos = Owner.EyePos;
var dir = Owner.EyeRot.Forward;
var tr = Trace.Ray( startPos, startPos + dir * MaxTraceDistance )
.Ignore( Owner )
.HitLayer( CollisionLayer.Debris )
.Run();
if ( !tr.Hit )
return;
if ( !tr.Entity.IsValid() )
return;
if ( tr.Entity.IsWorld )
return;
var body = tr.Body;
if ( !body.IsValid() )
return;
var direction = tr.EndPos - tr.StartPos;
var distance = direction.Length;
var ratio = (1.0f - (distance / MaxDistance)).Clamp( 0, 1 ) * (push ? 1.0f : -1.0f);
var force = direction * (Force * ratio);
if ( Massless )
{
force *= body.Mass;
}
body.ApplyForceAt( tr.EndPos, force );
}
}
}
}