CaveSculptor.cs
/// <summary>
/// Lets the lizard reshape the cave where it looks: hold one key to dig into the rock, another to
/// raise it. Off while a skin is worn (people don't dig rock with their hands).
/// </summary>
[Title( "Cave Sculptor" ), Category( "Player" ), Icon( "construction" )]
public sealed class CaveSculptor : Component
{
/// <summary>Input action held to dig. "Flashlight" is bound to F.</summary>
[Property] public string DigAction { get; set; } = "Flashlight";
/// <summary>Input action held to raise rock. "Reload" is bound to R.</summary>
[Property] public string RaiseAction { get; set; } = "Reload";
/// <summary>How far away the rock can be worked, from the camera.</summary>
[Property] public float Reach { get; set; } = 900f;
/// <summary>Size of the area affected, in inches.</summary>
[Property] public float BrushRadius { get; set; } = 170f;
/// <summary>How fast the rock moves, in inches per second at the brush centre.</summary>
[Property] public float Strength { get; set; } = 260f;
protected override void OnUpdate()
{
bool dig = !string.IsNullOrEmpty( DigAction ) && Input.Down( DigAction );
bool raise = !string.IsNullOrEmpty( RaiseAction ) && Input.Down( RaiseAction );
if ( dig == raise ) return;
var wearer = Components.Get<SkinWearer>();
if ( wearer.IsValid() && wearer.IsWearing ) return;
var cam = Scene.Camera;
if ( !cam.IsValid() ) return;
var from = cam.WorldPosition;
var tr = Scene.Trace.Ray( from, from + cam.WorldRotation.Forward * Reach )
.IgnoreGameObjectHierarchy( GameObject )
.WithoutTags( "debris" )
.Run();
if ( !tr.Hit || !tr.GameObject.IsValid() ) return;
var cave = tr.GameObject.Components.Get<CaveGenerator>();
if ( cave is null ) return;
cave.Deform( tr.HitPosition, BrushRadius, (dig ? -1f : 1f) * Strength * Time.Delta );
}
}