A (Probably Simple) Mathematic Question
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!
Thank you for your time and reading!
asked Dec 21 '14 at 11:53 PM in Blueprint Scripting
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.
answered Dec 22 '14 at 04:45 AM
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?
answered Dec 22 '14 at 12:12 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here