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:
83
code/tools/Wheel.cs
Normal file
83
code/tools/Wheel.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
namespace Sandbox.Tools
|
||||
{
|
||||
[Library( "tool_wheel", Title = "Wheel", Description = "A wheel that you can turn on and off (but actually can't yet)", Group = "construction" )]
|
||||
public partial class WheelTool : BaseTool
|
||||
{
|
||||
PreviewEntity previewModel;
|
||||
|
||||
protected override bool IsPreviewTraceValid( TraceResult tr )
|
||||
{
|
||||
if ( !base.IsPreviewTraceValid( tr ) )
|
||||
return false;
|
||||
|
||||
if ( tr.Entity is WheelEntity )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override void CreatePreviews()
|
||||
{
|
||||
if ( TryCreatePreview( ref previewModel, "models/citizen_props/wheel01.vmdl" ) )
|
||||
{
|
||||
previewModel.RotationOffset = Rotation.FromAxis( Vector3.Up, 90 );
|
||||
}
|
||||
}
|
||||
|
||||
public override void Simulate()
|
||||
{
|
||||
if ( !Host.IsServer )
|
||||
return;
|
||||
|
||||
using ( Prediction.Off() )
|
||||
{
|
||||
if ( !Input.Pressed( InputButton.Attack1 ) )
|
||||
return;
|
||||
|
||||
var startPos = Owner.EyePos;
|
||||
var dir = Owner.EyeRot.Forward;
|
||||
|
||||
var tr = Trace.Ray( startPos, startPos + dir * MaxTraceDistance )
|
||||
.Ignore( Owner )
|
||||
.Run();
|
||||
|
||||
if ( !tr.Hit )
|
||||
return;
|
||||
|
||||
if ( !tr.Entity.IsValid() )
|
||||
return;
|
||||
|
||||
var attached = !tr.Entity.IsWorld && tr.Body.IsValid() && tr.Body.PhysicsGroup != null && tr.Body.Entity.IsValid();
|
||||
|
||||
if ( attached && tr.Entity is not Prop )
|
||||
return;
|
||||
|
||||
CreateHitEffects( tr.EndPos );
|
||||
|
||||
if ( tr.Entity is WheelEntity )
|
||||
{
|
||||
// TODO: Set properties
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var ent = new WheelEntity
|
||||
{
|
||||
Position = tr.EndPos,
|
||||
Rotation = Rotation.LookAt( tr.Normal ) * Rotation.From( new Angles( 0, 90, 0 ) ),
|
||||
};
|
||||
|
||||
ent.SetModel( "models/citizen_props/wheel01.vmdl" );
|
||||
|
||||
ent.PhysicsBody.Mass = tr.Body.Mass;
|
||||
|
||||
ent.Joint = PhysicsJoint.Revolute
|
||||
.From( ent.PhysicsBody )
|
||||
.To( tr.Body )
|
||||
.WithPivot( tr.EndPos )
|
||||
.WithBasis( Rotation.LookAt( tr.Normal ) * Rotation.From( new Angles( 90, 0, 0 ) ) )
|
||||
.Create();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user