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.
- Listed in Global namespace: E to H
- Documented in Items, interaction and damage
Constructors
| Member | What it is |
|---|---|
GrabAssistController(Interactor interactor, LayerMask collisionMask, Action onAttemptInteraction) | Creates a GrabAssistController from interactor, collisionMask and onAttemptInteraction. |
Fields
| Member | What it is |
|---|---|
Action GrabAssistEnded | Raised when the assist search stops. |
Action GrabAssistStarted | Raised when the assist search starts. |
Action<GrabAssistEventData> GrabAssistUpdated | Raised each frame of the search with whether there is a target and the line to draw. |
11 private and internal fields
| Member | What it is |
|---|---|
private readonly RaycastHit[] assistOverlap | Buffer for the sphere-cast hits. |
private readonly LayerMask collisionMask | Layers the sphere-cast searches. |
private Material grabAssistPathMaterial | Unused in this build. |
private readonly int handInversion | -1 for the right hand, 1 for the left, to mirror the assist direction. |
private readonly Interactor interactor | The interactor (hand) this assist belongs to. |
private bool isEnabled | Whether grab assist is on. |
private Interactable lastGrabAssistTarget | Target found by the last search, grabbed on the next grab attempt. |
private readonly Action OnAttemptInteraction | Callback from the interactor, called on each grab attempt. |
private float startGrabAssistTimeStamp | Time the current search started, for the start delay. |
private IUnityUpdateMethod updateAssist | Update registration while the search is running. |
private readonly GrabAssistView view | Visuals for the assist line. |
Properties
3 private and internal properties
| Member | What 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
| Member | What 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
| Member | What 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: