# Aim assist-- How to cast a wedge in screen space

My character exists in a 3D, isometric, top-down world.

I'd like to make an aim assist mechanic, such that when holding the right joystick in a direction the game will choose the enemy roughly in that direction from from the character.

i.e. when holding the stick left, an enemy to the left of them on the screen is chosen, even if that enemy is above them on a cliff in gamespace.

The issue that's confusing me is searching through enemies in screen-space.

My best idea for a solution would be to transform all targetable objects into screen space when the stick is held, compute the "distance from line" of all of them, sort, and choose the smallest (where the line is a line drawn from the character's screen coordinates in the direction of choice).

Can anyone think of a cheaper way to do this? Maybe a hack where I could take advantage of isometrics? I may have hundreds of targetable objects on screen at once and I'd to be able to do this every frame.

• Transforming a few hundred objects to screen space each frame does not sound like a heavy load for a modern device, even a phone. And you can use a spatial partition or bounds check to skip any that are nowhere near your line. But you could also invert your projection function to map the joystick direction into the isometric world space and do your check there. What part do you need help with? Dec 3, 2021 at 0:57
• @DMGregory thanks, I guess I just needed a sanity check that this wouldn't be too expensive to do this every frame. It makes sense, since it should vary linearly with the number of valid targets on screen/in some spatial bound. Dec 4, 2021 at 20:41
• After trying a few ways, I think I'm going to actually take the dot product of a vector cast out from the character -> target * vector cast out from the character -> direction of control stick and get the smallest result. Either way, I suppose this would be linear complexity w/ under 100 input, so I am probably overthinking it a bit Dec 4, 2021 at 20:42
• If you find that solution works well for you, be sure to post it as an Answer below. If you find it doesn't, try editing your question to clarify the issue. Dec 4, 2021 at 20:45