Skip to main content

TrainingHittingTool

A class in Root.Township, the global namespace.

A training dummy part that swings on a curve and re-arms its impactor once per cycle. Both sides run the swing; new players get the current progress on connect.

Constructors​

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

Fields​

9 private and internal fields
MemberWhat it is
private Collider activeColliderCollider that can hit; turned off after a hit and back on each new cycle.
private Quaternion baseRotationThe parent's rotation at Start, which the swing is applied on top of.
private float currentProgressHow far through the current swing cycle it is, 0 to 1.
private FixedImpactor fixedImpactorImpactor charged at the start of each cycle.
private Vector3 rotationAxisAxis the swing rotates around.
private DurationCurve rotationOverTimeSwing angle curve and cycle duration.
private MethodSync syncSync message (SyncA) for currentProgress.
private Rigidbody targetRigidbodyThe rigidbody that is rotated.
private ImpactTool toolThe impact tool whose collisions are watched.

Methods​

MemberWhat it is
override void Initialize()Sets up the progress sync message.
override void OnConnected(Player player)Sends the current swing progress to the joining player.
6 private and internal methods
MemberWhat it is
private void Awake()Hooks the tool's collision event.
private void Collided(Collision collision, bool isHitting, ImpactTool tool)Turns off the active collider after the tool hits something, so it hits once per swing.
private void FixedUpdate()Advances the swing progress; at the end of each cycle wraps round, re-enables the collider and charges the impactor.
private void Start()Records the parent's rotation as the base rotation.
private void Sync(IPlayer player, Stream stream)Serializes currentProgress as a 0 to 1 float.
private void UpdateRotation()Rotates the rigidbody around rotationAxis by the curve's angle at the current progress.