Skip to main content

TimberPiece

A class in Root.Township, Alta.Carpentry.

One piece of a carpentry timber block that tilts away as it is chiselled until it breaks off. The server applies damage; progress syncs to clients.

Constructors​

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

Fields​

17 private and internal fields
MemberWhat it is
private Vector3 baseLocalPositionThe piece's local position before any chiseling, used as the base for the tilted pose.
private Vector3 currentHittingDirectionDirection of the first hit, in the parent's space; later hits can only turn the pivot so far from it.
private AnimationCurve damageMultiplierOverChiselDistanceCurve that scales damage by the squared distance between the hit and the current chisel point.
private MeshFilter filterThe piece's MeshFilter, returned by MeshFilter.
private float healthToughness of the piece; damage is divided by this (and by the timber's material density when set).
private bool inversedUpWhether the piece sits upside down on the block; flips the rotation axis, and flipping the block the other way knocks progress back.
private AnimationCurve leniencyOverProgressCurve that gives a minimum hit-direction leniency as progress grows.
private float maxProgressOnFirstHitCaps progress from the first hit so one strike can't finish the piece (0 turns it off).
private float maxProgressOnRotateProgress the piece drops back to when the block is flipped before the piece is done (default 0.2).
private float maxRotationFromPivotHow far, per unit of progress, a later hit can turn the pivot direction away from the first hit (radians).
private Vector3 pivottingDirectionThe direction the piece is being knocked over in, in the parent's space. Saved and synced.
private float progressHow far the piece is chiseled off, from 0 to 1; at 1 it is done. Backing field for Progress.
private AnimationCurve progressionToAngleCurve that maps progress to the tilt angle in degrees.
private AnimationCurve recedingChiselPointCurve that moves the chisel point along the pivot direction as progress grows.
private TimberPiece.RotationModel rotationModelWorks out the rotation axis and pivot distance from the pivot direction and size.
private Vector3 sizeDimensions of the piece, used to find the edge it pivots over.
private TimberBlock timberBlockThe block this piece belongs to; its physical material's density changes chisel toughness.

Properties​

MemberWhat it is
Vector3 CurrentChiselPoint { get; }The point where chisel hits do the most good, moving as the piece tilts.
bool HasDirection { get; private set; }True after the first hit sets the direction the piece will tilt.
Vector3 HittingDirection { get; }World direction the piece should be hit in.
bool IsInversedUp { get; }Whether the piece's tilt is flipped (the block is upside down).
override MeshFilter MeshFilter { get; }The mesh filter on the piece.
override float Progress { get; set; }Chiselling progress from 0 to 1. Setting it tilts and moves the piece to match.

Methods​

MemberWhat it is
override void GetDirectionLeniency(ref float multiplier)Raises the chisel direction multiplier as progress grows, so later hits can be less precise.
override float GetHitMultiplier(Vector3 hitDirection)How well a hit direction lines up with the piece. Before the first hit, horizontal hits score best.
override void Load(PieceSaveData data)Restores progress and direction from save data.
override void ReceiveDamage(float damage, Vector3 position, Vector3 direction, ChiselingTool tool, Collider hitCollider)Server: adds progress from a chisel hit, scaled by distance to the chisel point and the block's density.
override void Rotate(bool isInversedUp)Pulls progress back down to a cap when the block is flipped before the piece is done.
override PieceSaveData Save()Returns the piece's progress and directions as save data.
override void Serialize(Stream stream, bool isWritingFull)Syncs progress and direction. Clients show a damage popup when it changes.
protected override void Awake()Caches the mesh filter and sets up the tilt model.
2 private and internal methods
MemberWhat it is
private void OnDrawGizmosSelected()Editor: draws the current chisel point and the hitting direction.
private void OnValidate()Editor: records the base local position while progress is zero, then reapplies Progress to update the pose.

Used in​

Members of other types that take, return or hold a TimberPiece: