Skip to main content

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.

Constructors​

MemberWhat it is
ChiselingTool()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

18 private and internal fields
MemberWhat it is
private Vector3 chiselingDirectionLocal direction the chisel cuts in. Backs ChiselingDirection.
private Vector3 chiselingPointLocal position of the chisel tip. Backs ChiselingPoint.
private int collisionCountNot used in this class.
private float damageMultiplierMultiplies hit damage dealt to the chiseled piece. 3 by default.
private float dotPrecisionPower applied to the piece's direction multiplier, so off-angle hits count less. 1 by default.
private Coroutine hapticThe running TouchHaptic coroutine, or null.
private float hapticRayCastDistanceHow far ahead of the tip haptics check for a chiselable. 0 checks only at the tip.
private AnimationCurve hapticsOverDistanceFromGhostHandHaptic strength by squared distance between the hand and its ghost hand.
private Collider hitColliderCollider of the piece found by the last CheckForPiece.
private IChiselable hitPieceChiselable found by the last CheckForPiece, used and cleared by the next hit.
private Vector3 hitPositionPoint on the piece found by the last CheckForPiece.
private int layerMaskMask of the Default layer, which the chisel casts check.
private PhysicalMaterialPart materialPartPhysical material part on the tool, whose damage multiplier scales chisel damage.
private float maxChiselingDistanceLength of the sphere cast from the tip when looking for a piece.
private static Collider[] nonAllocCollidersShared buffer for overlap checks.
private static RaycastHit[] nonAllocRaycastHitsShared buffer for sphere casts.
private float physicalMaterialMultiplierThe tool material's damage multiplier. 1 when there is no material.
private float sphereCastRadiusRadius of the chisel casts. 0.01 by default.

Properties​

MemberWhat 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​

MemberWhat 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
MemberWhat 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: