
I am trying to get positional data in a circle around my player (top down camera) divided into 4 quadrants (ideally 8 at some stage) from the centre point (where the player is). So if an enemy is anywhere in the top segment I know when I am hit to tell the transform to send me down.
I have a very basic setup to calculate where the enemy is in relation to the player and vice versa but it is severely flawed and only works for 3 directions, no matter what I do or which order I run it in, one will always default to another direction.

(disconnected from other code for clarity)
The problem with this is that it is incredibly basic and it doesn’t give an accurate representation to where the enemy is in relation to the player.
I am sure that math has the answer…
Save me and my undereducated soul
Hi , check out rotators, you can use the find look at rotation to get the rotation from your char to the enemy and then you could use the delta to see where they are in relation to your rotation.
https://docs.unrealengine.com/latest/INT/BlueprintAPI/Math/Rotator/FindLookatRotation/index.html
https://docs.unrealengine.com/latest/INT/BlueprintAPI/Math/Rotator/Delta_Rotator/index.html
Thanks, I don’t use rotation on any actor in game, they are rotationally locked. Hmm will this be an issue?
Would it be possible for you to provide a quick example of how I would set this up? It is the first time I have come across both of these nodes and I am unsure how I would use the final return from the delta to calculate my quadrants.
It seems to be printing positional data as is but how would I go about translating that to my enum directions effectively (up, right, down, left)? Or better yet avoid them completely as they are mostly redundant and have full 360 deg knockbacks relative to the enemy!
Thanks , looks promising
No problem, check out the screen below. I just added an actor variable to the third person char so I could select anything in the world, in this case a cube.
On tick I generate a rotator, the yaw value in the rotator is what you want. If you print it out, you’ll see it change as you move around the object. So in your case, you can define ranges, such as if the pos is between 0 and 90.
Thanks for getting back to me, but I might have some issues still due to how my project is setup. This wouldn’t be the first one either due to having locked rotation and using sprite Flipbooks… Crafting AI without being able to use normal UE4 AI nodes was fun… 
(Currently placement art until systems have been finalised)
As you can see I receive no rotational value as my player and enemies (in this example the statue I am walking into) have a locked rotation to prevent the sprite from rotating away from the camera. So using your example I am limited again to the same directional data (in this case P and Y instead of X and Y), or am I missing something else?
This is quite a unique problem as most people will be using UE4 to build 3d games and sprites are largely redundant, especially 2d/3d crossovers. I may have shot myself in the foot with this project!..
Any advice? I am considering if it is possible to have a non-visible rotating element within the player controller/enemy blueprints but this could be too complicated to implement to be worthwhile, especially when there could be a mathematical solution that could help
You can Inverse-Transform position of the enemy into local coordinate system of the player. Then just check if X and Y coordinate is positive or negative, this will tell you if enemy is “above/bellow” or to the left/right from the player.
The way it’s done is following:
Get World Space Transform of the “player” (it could be a pawn or anything derived from UActor as you need only transform). Using this transform call function InverseTransfromPosition (or InverseTranformLocation, don’t remember) as input to this function, plug in position of the enemy. The result of this function is a position of the enemy as if player would be the center of the world. Such transformation will take into account rotation as well, if you are not rotating anything it doesn’t matter.
Thanks,
I got it working in the end thanks to your suggestion. It’s not the solution I had in mind but it does the job at breaking down the quadrants in a more efficient fashion than before.
For anyone else interested, I used in conjunction with a InRange(Float) on each of the Inverse Transform Locations for +/- floats before defining the enum. This prevented overlap from the transforms/regions causing the player to knockback left when it should knockback up instead.
You can do a dot product between X and Y axis and direction to enemy after it was inverse transformed. Like this:
(1.0, 0.0, 0.0) . Normalize(EnemyPositionLocalSpace)
If result is > 0.707 then enemy is in left quadrant (assuming left/right is on X axis)
If result is < -0.707 then enemy is in right quadrant
Same logic for Y axis
Ah-ha!
Thanks for the addition. I haven’t fully explored this region of blueprints yet and a lot of nodes are still a mystery to me, so it’s good to hear an explanation. I dream of the day where every node has a wiki entry with examples of usage/a description of their common functions. Until then it’s good guys like you keeping us all up to speed, thanks!
Some of these things are cross engine math, you either know how it works or you don’t. It would be difficult to explain what dot product does in UE4 Wiki. I mean look at this
Dot product - Wikipedia and it doesn’t actually list all potential applications.
For gamedev vector math, dot product is usually used to measure how similar two vectors are, calculate projection or just to find absolute angle between vectors. Dot product is a cosine of the angle between vectors. This is how values look like for different “configurations” of unit vectors (normalized vectors): Range of the Dot Product of Two Unit Vectors
[so I’ve made a mistake in my post - you need to compare dot product value to 0.707 instead of 0.5, quite embarrassing :D]
In case of projection, in UE4 you already have node for it. It’s very useful for variety of things. Like you can measure how much of the objects velocity is aligned with it’s forward vector by projecting velocity vector onto forward vector. But it’s not limited to this, just as in case of dot product. Learning math by examples of how something can be used, can be useful, but in long run it can lead to mistakes. Just as I did in previous post.
Thank you both for the resources, I never took math seriously in my youth and didn’t take it as a chosen subject (which I regret as it is crucial to so many aspects of game dev) so I guess I have some reading to do! But both of these examples showcase what it is I am trying to achieve, it is just a case now of understanding the why and how.
I appreciate the help guys, I will have to experiment later after work and read through everything properly.