ChiselingTool
A class in Root.Township, Alta.Carpentry.
Impact detector on a chisel that finds the nearest chiselable piece ahead of its tip and passes hits to it, scaled by the chisel's material. Also gives touch haptics near chiselable pieces.
- Listed in Crafting and making
- Inherits or implements
CraftableImpactDetectorBase - Documented in Farming, woodcutting and carpentry
Constructors
| Member | What it is |
|---|---|
ChiselingTool() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
18 private and internal fields
| Member | What it is |
|---|---|
private Vector3 chiselingDirection | Local direction the chisel cuts in. Backs ChiselingDirection. |
private Vector3 chiselingPoint | Local position of the chisel tip. Backs ChiselingPoint. |
private int collisionCount | Not used in this class. |
private float damageMultiplier | Multiplies hit damage dealt to the chiseled piece. 3 by default. |
private float dotPrecision | Power applied to the piece's direction multiplier, so off-angle hits count less. 1 by default. |
private Coroutine haptic | The running TouchHaptic coroutine, or null. |
private float hapticRayCastDistance | How far ahead of the tip haptics check for a chiselable. 0 checks only at the tip. |
private AnimationCurve hapticsOverDistanceFromGhostHand | Haptic strength by squared distance between the hand and its ghost hand. |
private Collider hitCollider | Collider of the piece found by the last CheckForPiece. |
private IChiselable hitPiece | Chiselable found by the last CheckForPiece, used and cleared by the next hit. |
private Vector3 hitPosition | Point on the piece found by the last CheckForPiece. |
private int layerMask | Mask of the Default layer, which the chisel casts check. |
private PhysicalMaterialPart materialPart | Physical material part on the tool, whose damage multiplier scales chisel damage. |
private float maxChiselingDistance | Length of the sphere cast from the tip when looking for a piece. |
private static Collider[] nonAllocColliders | Shared buffer for overlap checks. |
private static RaycastHit[] nonAllocRaycastHits | Shared buffer for sphere casts. |
private float physicalMaterialMultiplier | The tool material's damage multiplier. 1 when there is no material. |
private float sphereCastRadius | Radius of the chisel casts. 0.01 by default. |
Properties
| Member | What it is |
|---|---|
Vector3 ChiselingDirection { get; } | World direction the chisel points. |
Vector3 ChiselingPoint { get; } | World position of the chisel's tip. |
ImpactHit LastHit { get; private set; } | The last impact that hit a piece, or null if the last impact missed. |
Methods
| Member | What it is |
|---|---|
bool CheckForPiece(out float directionMultiplier) | Sphere-casts from the tip for the closest enabled chiselable piece and works out the direction multiplier. True if one was found. |
protected override void Awake() | Hooks the hit event and the material part so the damage multiplier follows the chisel's material. |
protected override void PreReceiveSyncedHit() | Looks for a piece again before applying a hit synced from elsewhere. |
protected override void UpdateTool(ImpactTool registeringTool) | Moves the haptic and collision filter hooks to a new impact tool. |
protected override bool ValidateContatPoint(ContactPoint point) | Accepts every contact point. |
9 private and internal methods
| Member | What it is |
|---|---|
private void CalculateTouchHapitcs() | Pulses the holding hands when the chisel tip touches a chiselable that triggers haptics. |
private void ConsumeFilter(ref bool isHitconsumed) | Tool collision filter: marks the hit as consumed when a chiselable is in front of the tip. |
private void HitPiece(ImpactHit impact) | Hit handler: damages the chiselable found by CheckForPiece, scaled by damage and material multipliers. Server also wears the tool. |
private void NewMaterial(PhysicalMaterial physicalMaterial, PhysicalMaterialChannel materialChannel) | Updates physicalMaterialMultiplier when the tool's material changes. |
private void OnDrawGizmosSelected() | Editor: draws the tip, the chisel cast and the haptic cast. |
private void StartCheckHaptic(Interactable interactable, Interactor interactor) | Starts the TouchHaptic loop when a local hand grabs the tool. |
private void StopCheckHaptic(Interactable interactable, Interactor interactor) | Stops the haptic loop when the tool is no longer held. |
private IEnumerator TouchHaptic() (iterator) | Coroutine that runs CalculateTouchHapitcs every frame while the tool is held. |
private void TriggerHaptic(Interactor interactor) | Pulses a local hand, stronger the further the real hand is from its ghost hand. |
Used in
Members of other types that take, return or hold a ChiselingTool:
Chiselable.ReceiveDamage, ChiselHit.BeginInvoke, ChiselHit.Invoke, IChiselable.ReceiveDamage, TimberPiece.ReceiveDamage, TimberPieceBase.ReceiveDamage, TimberPieceGroup.ReceiveDamage, CraftingPieceChiselable.ReceiveDamage, DecraftingComponent.TryDecraft, BasicChiselable.OnBrokenServer, BasicChiselable.OnDamageTakenServer, BasicChiselable.ReceiveDamage, ChiselableSurfaceDock.OnBrokenServer, ChiselableSurfaceDock.OnDamageTakenServer.