Skip to main content

GrabAssistController

A class in Root.Township, the global namespace.

Client helper on each Interactor that runs grab assist: while the grab assist action is held and the hand points down, it sphere-casts for a pickup and grabs it from a distance. Created by Interactor, with a GrabAssistView for the visuals.

Constructors​

MemberWhat it is
GrabAssistController(Interactor interactor, LayerMask collisionMask, Action onAttemptInteraction)Creates a GrabAssistController from interactor, collisionMask and onAttemptInteraction.

Fields​

MemberWhat it is
Action GrabAssistEndedRaised when the assist search stops.
Action GrabAssistStartedRaised when the assist search starts.
Action<GrabAssistEventData> GrabAssistUpdatedRaised each frame of the search with whether there is a target and the line to draw.
11 private and internal fields
MemberWhat it is
private readonly RaycastHit[] assistOverlapBuffer for the sphere-cast hits.
private readonly LayerMask collisionMaskLayers the sphere-cast searches.
private Material grabAssistPathMaterialUnused in this build.
private readonly int handInversion-1 for the right hand, 1 for the left, to mirror the assist direction.
private readonly Interactor interactorThe interactor (hand) this assist belongs to.
private bool isEnabledWhether grab assist is on.
private Interactable lastGrabAssistTargetTarget found by the last search, grabbed on the next grab attempt.
private readonly Action OnAttemptInteractionCallback from the interactor, called on each grab attempt.
private float startGrabAssistTimeStampTime the current search started, for the start delay.
private IUnityUpdateMethod updateAssistUpdate registration while the search is running.
private readonly GrabAssistView viewVisuals for the assist line.

Properties​

3 private and internal properties
MemberWhat it is
private Vector3 GrabAssistDirection { get; }Direction of the assist ray from the hand, mirrored for the right hand.
private Vector3 GrabAssistOrigin { get; }Start of the assist ray, at the interactor's trigger object.
private static GrabAssistSettings Settings { get; }The global GrabAssistSettings.

Methods​

MemberWhat it is
bool CheckGrabAssist()If grab assist has a valid target, grabs it and returns true.
void CheckGrabOrStartUpdatingGrabAssist()On a grab attempt: uses the assist target, else the best nearby interactable, else starts searching.
void Disable()Turns grab assist off and unhooks the grab assist action.
void StopUpdatingGrabAssist(PlayerInput _, bool __)Stops the search, clears the target and raises GrabAssistEnded.
17 private and internal methods
MemberWhat it is
private float AdjustLengthForObstacles(Vector3 grabAssistDirection, float baseGrabAssistLength)Shortens the search to the first obstacle hit along the assist direction.
private float DotProductFromDown(Vector3 grabAssistDownDirection)How much a direction points down, from -1 to 1.
private void Enable()Turns grab assist on and hooks the grab assist action's start and end.
private float GetAssistGrabTargetScore(AssistGrabInteractable grabInteractable, float previousLowestScore)Score for an AssistGrabInteractable, if it is a root entity on a shared channel and can be interacted with.
private Vector3 GetClosestPointOnPickup(Pickup lastPickup, Vector3 origin, Vector3 closestPoint)Closest point on the pickup's solid default-layer colliders, falling back to its best grab point.
private Vector3 GetClosestPointOnTarget(Vector3 origin)Point on the current target the assist line ends at.
private float GetInteractableScore(Interactable interactable, float previousLowestScore)Scores a hit pickup or assist-grab interactable; other types get no score.
private int GetOverlapCount(Vector3 grabAssistDirection, float adjustedLength)Sphere-casts along the assist direction and stores up to 10 hits.
private float GetPickupTargetScore(Pickup pickup, float previousLowestScore)Score for a pickup if it is free, not docked, not moving, allowed to assist grab and can be interacted with.
private static float GetSearchableLength(Vector3 grabAssistDirection)Search length from settings, longer the more the hand points straight down.
private Interactable GetTarget(int overlapCount)Picks a target from the sphere-cast hits. It keeps the last valid hit, not the lowest score, as the best score is never updated.
private Vector3 GetTargetPosition(Vector3 grabAssistDirection, bool hasTarget, float length)Where the assist line ends: on the target, or at the end of the search.
private bool HasStartDelayTimeElapsed()True once the settings' start delay has passed since the search began.
private bool IsWithinActiveAngle(Vector3 grabAssistDirection)True when the hand points down enough for assist to work.
private void OnSettingsChanged(Settings _)Turns assist on or off from the game setting. It is never subscribed in this build, only unsubscribed.
private void StartUpdatingGrabAssist(PlayerInput _)Starts the per-frame target search unless grab assist is blocked.
private void UpdateAssistTarget()Per-frame search: finds the target along the assist ray and raises GrabAssistUpdated.

Used in​

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