Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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!

alt text

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!

Product Version: Not Selected
capture.jpg (24.5 kB)
more ▼

asked Dec 21 '14 at 11:53 PM in Blueprint Scripting

avatar image

782 38 34 70

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

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.

more ▼

answered Dec 22 '14 at 04:45 AM

avatar image

690 36 35 74

avatar image Achilleon Dec 22 '14 at 08:21 AM

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

avatar image Achilleon Dec 22 '14 at 08:30 AM

Works perfect. Thank you. ^_^

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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?

more ▼

answered Dec 22 '14 at 12:12 AM

avatar image

298 21 16 43

avatar image 1l2Hawk Dec 22 '14 at 04:54 AM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question