Skip to main content

CharacterIKController

A class in Root.Township, the global namespace.

Runs a player character's IK (body following head and hands) and lets it be turned off, for example for out-of-body moments, with the change synced to other players. On every player character.

Constructors​

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

Fields​

14 private and internal fields
MemberWhat it is
private CharacterComponentControllerCollection characterComponentControllersThe IK component controllers updated by FixedUpdateIK and UpdateIK.
private Transform headTargetTransform the head IK follows.
private Transform headTargetLocalParentParent for the head target when this is the local player.
private Transform headTargetRemoteParentParent for the head target when this is a remote player.
private SerializableTransform headTargetTransformSaved local transform restored on the head target when IK is enabled.
private bool isAutomaticallyFillingTargetTransformInspector button flag that triggers AutomaticallyFillTargetTransforms.
private HandTargetHandler leftHandTargetLeft hand IK target handler.
private Transform leftHandTargetParentParent restored on the left hand target when IK is enabled.
private SerializableTransform leftHandTargetTransformSaved local transform restored on the left hand target when IK is enabled.
private static Logger loggerNLog logger for this class.
private PlayerCharacter playerCharacterThe player character this controller drives.
private HandTargetHandler rightHandTargetRight hand IK target handler.
private Transform rightHandTargetParentParent restored on the right hand target when IK is enabled.
private SerializableTransform rightHandTargetTransformSaved local transform restored on the right hand target when IK is enabled.

Properties​

MemberWhat it is
bool IsIKControlActive { get; private set; }True while IK drives the hand and head targets.
1 private and internal property
MemberWhat it is
private bool ShouldUpdate { get; }True when IK should run: the player is alive and, in the editor or on Quest for the local player, the app has input focus.

Events​

MemberWhat it is
event UpdateHandler IKUpdatesFinishedRaised after the body IK has updated. Held items such as keys use it to reposition.
event UpdateHandler PreIKUpdatesRaised before the IK components update. Bow strings and ropes use it.
event UpdateHandler PreRenderCallbackRaised after IKUpdatesFinished, once IK is done for the frame.

Methods​

MemberWhat it is
void DisableIKControl(IKControllSettings settings)Detaches the hand and head targets from IK, optionally disabling IK fully and showing ghost hands. Local players sync it to others.
void DisableIKControl(out Transform leftHandTarget, out Transform rightHandTarget, IKControllSettings settings)Detaches the hand and head targets from IK, optionally disabling IK fully and showing ghost hands. Local players sync it to others.
void EnableIKControl(IKControllSettings settings)Puts the hand and head targets back under IK. Local players sync it to others. Logs an error if already active.
void FixedUpdateIK()Runs the IK components' fixed update while the player is alive (and has input focus in the editor or on Quest).
override void Initialize()Registers the handler for IK enable and disable messages. The server relays them to other players.
void OnBodyIKFinished()Raises IKUpdatesFinished then PreRenderCallback, logging any handler errors.
void OnPreIKUpdate()Raises PreIKUpdates, logging any handler errors.
void SetConstantGhostHandVisibility(bool isAlwaysVisible)Forces both ghost hands fully visible, or hands them back to their normal fading.
void UpdateIK()Runs the IK components' update while the player is alive (and has input focus in the editor or on Quest).
5 private and internal methods
MemberWhat it is
private void AutomaticallyFillTargetTransforms()Editor: saves the current hand and head target parents and transforms so IK can be restored later.
private void Awake()Marks IK control active and hooks the component controllers' pre and post update events.
private void IInitializeAsLocalPlayer.InitializeAsLocalPlayer(PlayerController player)Marks the component controllers as local.
private void OnValidate()Editor: runs AutomaticallyFillTargetTransforms when its inspector button is pressed.
private void SyncWithRemote(IPlayer player, Stream stream)Handles an IK controller message: enables or disables IK to match, and the server relays it to the other players in range.

Used in​

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