Iβm making a battle system where the player selects an enemy to focus, and the player presses Q or E to switch between them, targeting the nearest right or left enemy. I can already get the delta rotation between the player and the actor, and select the shortest one, however I have no idea on how to filter out the actors if they are to the left, or the right of the actor.
Well, several solutions are possible, and I will explain a simple one. If you think itβs not enough accurate for your needs, tell me
Current : Current selected target
Right : the item just at the right
Left : the item just at the left
The red arrow : represents a vector from the Player to the Target
The green arrow : represents the right vector of the [Player to the Target] vector
The yellow arrow : represents projections 2D of the location on the right vector
Here is the principle : you have to figure out what is the right axis for your player to be allow to determine what is the right and what is the left for the player.
I think the best for you is the right vector of the vector (Player to CurrentTarget).
To calculate it, you can use some maths :
We project the pawn location and the item location to make calculus on 2D. After that, we find the vector (Player to Target) and, using cross product, find the famous Right Vector.
From here, you have to find, among all targets, the one that is just to the left or just to the right.
For left, you have to fill the conditions :
the dot product is < 0
has the highest dot product among the other items
the item is not the current selected one
For right, it is the inverse :
the dot product is > 0
has the lowest dot product among the other items
the item is not the current selected one
You also have to care about the item locations to be projected since we are using 2D maths :
Here is the blueprint to find the left item :