Skip to main content

DiggingImpactor

A class in Root.Township, the global namespace.

Makes a tool (shovel head) bury itself in the ground when it hits a target layer hard enough, then dig up IDigable objects nearby when it is levered out. The holder's client decides bury and unbury and syncs it; dig damage runs on the server; the buried state is saved.

Constructors​

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

Fields​

18 private and internal fields
MemberWhat it is
private Vector3 buriedPositionWhere the tool sits while buried.
private Quaternion buriedRotationTool rotation while buried.
private Coroutine checkPullThe running CheckPull coroutine.
private ImpactTool currentToolThe impact tool being buried.
private Func<float> diggingDamageMultiplierServer: returns the physical material's damage multiplier, or 1.
private Transform digShereCastPositionWhere the digable search sphere is centred (at the pivot's height).
private Pickup durabilityPickupPickup whose durability drops on each dig.
private float efficiencyRatioHow well the hit landed, 0 to 1; drives depth, pull, radius and damage. Saved as -1 when not buried.
private FakePickup fakePickupGrab point that holds the tool in the ground and is pulled to unbury it.
private Dictionary<Interactor, DiggingImpactor.InteractorPositions> interactorPositionsStart position and lever distance of each hand on the fake pickup.
private static Logger loggerNLog logger.
private Vector3 pivotGround hit point the tool levers around.
private Vector3 pullOutDirectionLocal direction for pulling the tool straight out.
private Action receivedToolCallback run when a tool is registered, used for DelayedBury.
private Vector3 rotatingAxisLocal axis used with the pull-out direction to work out the lever torque axis.
private DiggingImpactorSettings settingsDiggingImpactorSettings with thresholds, curves, layers and effects.
private MethodSync syncBuriedSync for the buried state.
private MethodSyncStruct<bool> syncUnburiedSync for unburying, with a dig flag.

Properties​

MemberWhat it is
bool IsBuried { get; private set; }Whether the tool is stuck in the ground.

Methods​

MemberWhat it is
override void Initialize()Sets up the buried and unburied syncs.
override void InitializeAsServer(SpawnData data)Server: sets the damage multiplier source and, if saved as buried, re-buries and syncs it next frame.
override void OnConnected(Player player)Server: sends the buried state to a joining player next frame.
16 private and internal methods
MemberWhat it is
private void Awake()Finds the impact tool, through the crafting root if there is one, and hooks the fake pickup's grab events.
private void Bury()Marks it buried, attaches the fake pickup to hold the tool in place, and plays the embed effect on clients.
private IEnumerator CheckPull() (iterator)While grabbed, totals hand movement; enough torque unburies and digs, enough straight pull unburies without digging.
private void DelayedBury()Applies a buried state that arrived before the tool was known, once the tool is registered.
private void Dig()Server: damages every digable in range by effectiveness and the material's damage multiplier, and wears the tool.
private void EndCheckPull(Interactor interactor)Stops tracking a hand, and stops CheckPull when no hands are left.
private IEnumerable<IDigable> FoundDigables() (iterator)Finds IDigable components on rigidbodies in a sphere at the dig point, sized by efficiency.
private void Alta.Impact.IToolHitDependant.OnCollided(Collision collision, bool isHitting, ImpactTool tool)On a hard enough ground hit (by the local holder, or the server if nobody holds it), buries the tool and syncs it.
private void OnDrawGizmosSelected()Draws the pull-out direction and torque axis.
private void Alta.Impact.IToolHitDependant.OnHit(ImpactHitWithTool hit, ImpactTool tool)Empty; only collisions matter.
private void OnRootChanged(CraftingPart part)Registers the new root's impact tool when the crafting root changes.
private void RegisterTool(ImpactTool newTool)Sets the current tool and points the fake pickup at its pickup.
private void StartCheckPull(Interactor interactor)When the local player grabs the fake pickup, records the hand's start and starts CheckPull; unburies if it wasn't buried.
private void SyncBuried(IPlayer player, Stream stream)Syncs efficiency, buried position, pivot and rotation, then buries the tool; the server relays it and notifies digables.
private void SyncUnburied(IPlayer player, Stream stream, bool isDigging)Syncs an unbury and whether it digs; the server relays it to others.
private void Unbury(bool isDigging)Marks it not buried, plays the dig effect and digs on the server if digging, and detaches the fake pickup.