Aim Assist, cycle targets w/ input key

swilderness

New member
Hello,

I was thinking of co-opting Aim Assist for a story adventure game and allowing the player to "aim" at different points of interest in the 3D world as a Look Around mode.

That part is pretty doable so far, but what I'm not clear on is how to cycle between available targets with an input key. I basically want players to be able to find all the nearby interactables in the laziest way possible. Like hit the tab key and the player locates and locks onto the next interactable: for example, a book, a window, the knife on the table, etc...

I see "switch target radius" in the docs, but I don't see where in the inspector the player can switch targets or how, and if it could be automatic.
 
I didn't use Aim Assist at all, but by looking in the code You can find a public method called TrySwitchSwitchTarget(bool);
And that function is trying to switch target (if it's possible, because sometimes You will dosen't have any target in radius). By passing parameter (bool => true/false) u will determine if the target should be on the right site of the camera.
To use this function just cache your AimAssist (e.g. from Inspector) and then i believe You can use it anywhere in the code like so.

Example:

C#:
AimAssist aimAssist = cameraObject.GetComponent<AimAssist>();
          
aimAssist.TrySwitchTargets(true);

which will try to switch target to the one of the right site of the camera :)


Also if it's not exactly what You need and You are familiar with programming, You can try to make your own script.
For example You can do a SphereCast to detect all colliders in the given radius, then You can iterate trought them and call TryGetComponent to check if objects has a Interactable component attached. If so, You can just add those object to previosuly created list/array for example "Interactable[] InteractableObjectsInArray". Even better will be to use NonAlloc version of SphereCast which give u an array of objects and you can re-use them without calling physics every time when u press Tab, but that can be a little tricky. But that's for performance :). With this collection of Interctable objects included, You can just simply calculate angle bettwen player and objects and rotate to object with smallest angle difference. Or use Vector3.Dot maybe, i think that also could work in that case. Like i said => that will require more programming skills, but You will have more control over this ability :) And because Opsive system is very flexible, You can even code this as a Player Ability, so you will be able to get full-advantages of Ultimate Character state system/input system/and rest of the systems :) This is up to You
 
Last edited:
Thank you! I was wondering if there was something like that (the switch targets option), but I'll definitely give the second approach a shot with PlayMaker. Thanks for pointing me in the right direction. :)
 
Top