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.
- Listed in Crafting and making
- Inherits or implements
TimberPieceBase - Nested types
RotationModel - Documented in Farming, woodcutting and carpentry
Constructors
| Member | What it is |
|---|---|
TimberPiece() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
17 private and internal fields
| Member | What it is |
|---|---|
private Vector3 baseLocalPosition | The piece's local position before any chiseling, used as the base for the tilted pose. |
private Vector3 currentHittingDirection | Direction of the first hit, in the parent's space; later hits can only turn the pivot so far from it. |
private AnimationCurve damageMultiplierOverChiselDistance | Curve that scales damage by the squared distance between the hit and the current chisel point. |
private MeshFilter filter | The piece's MeshFilter, returned by MeshFilter. |
private float health | Toughness of the piece; damage is divided by this (and by the timber's material density when set). |
private bool inversedUp | Whether the piece sits upside down on the block; flips the rotation axis, and flipping the block the other way knocks progress back. |
private AnimationCurve leniencyOverProgress | Curve that gives a minimum hit-direction leniency as progress grows. |
private float maxProgressOnFirstHit | Caps progress from the first hit so one strike can't finish the piece (0 turns it off). |
private float maxProgressOnRotate | Progress the piece drops back to when the block is flipped before the piece is done (default 0.2). |
private float maxRotationFromPivot | How far, per unit of progress, a later hit can turn the pivot direction away from the first hit (radians). |
private Vector3 pivottingDirection | The direction the piece is being knocked over in, in the parent's space. Saved and synced. |
private float progress | How far the piece is chiseled off, from 0 to 1; at 1 it is done. Backing field for Progress. |
private AnimationCurve progressionToAngle | Curve that maps progress to the tilt angle in degrees. |
private AnimationCurve recedingChiselPoint | Curve that moves the chisel point along the pivot direction as progress grows. |
private TimberPiece.RotationModel rotationModel | Works out the rotation axis and pivot distance from the pivot direction and size. |
private Vector3 size | Dimensions of the piece, used to find the edge it pivots over. |
private TimberBlock timberBlock | The block this piece belongs to; its physical material's density changes chisel toughness. |
Properties
Methods
| Member | What 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
Used in
Members of other types that take, return or hold a TimberPiece: