A (Probably Simple) Mathematic Question

Hello everyone!

I got a question. Though I prefer to explain it with a picture, which already shows what I aim to do!

Here is the story. There is a tree. And there is a player. The tree got a face, which is looking at where the arrow is pointing. Same goes for the player. What I need is, the words in white boxes. Basically I need the tree be able to figure out where he player is compared to where itself is staring at. In the picture for example, if we think that we are actually the tree, we would say “Player is at the left side of where I am currently staring at.”

The closest thing I could figure out was from the Door blueprint in Blueprint-Advanced map of Content Examples, where there is a calculation about whether the player is at back or front. Though unfortunately I couldn’t go that far no matter what I tried, so any help is appreciated!

If I understood the problem correctly. How about comparing the rotation of the tree itself with the look at rotation from tree to the player? Assuming 0 is up on the picture, the tree rotation yaw would be 180 and the look at rotation yaw would be ~160. So if it’s less than 180, the player is on the left and if it’s more than 180 it’s on the right?

You’ll first need to calculate two rotators. One is the direction the tree is facing, the other is a line from the tree to the player. By using a “Delta (Rotator)” node and checking it’s sign (positive or negative value), you’ll be able to tell if that player is in the red or blue areas. Here’s exactly how:

First, get the world rotation of the tree itself (assuming is face is pointing forward). This will get plugged into the A input of the Delta (Rotator). Easy enough.

Second, get the look at rotation to the player. This has one extra step in it. You’ll need a node called “Find Look At Rotation”, which takes two vector values as inputs. Feed the tree’s world location into Start - and the player’s world location into Target. This will give you a rotator that can be plugged into the B input of the Delta (Rotator).

Now you just need a simple Branch test to see whether that angle is greater than or less than zero. One way will mean the player is in the blue, the other then he’s in the red. Pretty sure this works even if the player ever gets in behind your tree too. Hope this helps.

This solution works okay for most parts of the circle, but can cause all sorts of headaches around the 360 degree mark where it resets back to 0 if you keep going. For example, tree is looking down the 355 degree line, small step left you get 345, small step right you get 5. Both values are less than 355, right. A more robust solution measures the angle between the two directly - per below.

Thank you both friends, I will try the solution asap. ^^

Works perfect. Thank you.