Cycling Player Lock-On Targets Using Thumbstick

Hello,

I’m trying to create a lock on system that allows me to cycle through potential targets.

Right now I have targeting and locking-on working fine. I click the right thumbstick button to find the closest enemy within my lock-on range and set them as the target.

How I would like it to function is by taking the horizontal direction of the right thumbstick and searching “within” that direction for a new target that is the closest to the current target. Think about it as a top-down 2D version of Dark Souls/Bloodbornes/Niohs targeting system.

I can’t think of an elegant way to achieve this. I’ve tried a few things but they’ve given very unpredictable results.

Any ideas?

How about firing a bunch of raycasts from the currently targeted object in the direction of the thumbstick? Apply target to first targetable object hit.

Tried doing that and it was very clunky and inaccurate. I cast several rays out evenly spaced within an angle towards the input direction from the current targets position.

I was hoping to make it so the target cycling doesn’t require actual aiming since for some reason it feels terrible gameplay wise.