x

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"

Issues with GetActorForwardVector

I seem to have encountered and unexpected behavior of the GetActorForwardVector() method.

I'm checking to actors forward vector against one another, and I'm noticing that one actors forward vector looks like this: X=0.000 Y=1.000 Z=0.000, while the others forward vector looks like this: X=-0.000 Y=1.000 Z=0.000. It's quite clear to see that they're both facing the same way on the Y axis, however, one seem to be negative on the X axis, whereas the other is not.

Is there a way for me to force the 0's to be positive, as I'm only interested in the 1's? :)

Product Version: UE 4.20
Tags:
more ▼

asked Oct 22 '18 at 06:46 PM in C++ Programming

avatar image

Detilium
71 3 9 10

avatar image Brian Johnstone Oct 22 '18 at 06:58 PM

The issue of -0 is a complex one. What do you need to use the numbers for? It might not be necessary to change the values at all depending on what you are trying to do. -0 is the same value as 0 when used in Vector operations.

avatar image Detilium Oct 22 '18 at 07:06 PM

I don't need the 0's I only need the 1's (getting the forward AXIS). So in this specific scenario, I have no use for the X axis, only the Y. Problem is of course, that the first vector is not equal to the second, since the X is negative/positive. I only need the value of the Y axis, but it might as well could've been the X axis. It's just the Y axis in this example.

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

2 answers: sort voted first

To see if they are facing each other, do a dot product of the two vectors instead

This way you get a single value to compare and is more manageable.
Have a look at this table for the values to expect depending on their facing directions

If both the actors face the same way, the value will be close to 1. If it is close to -1, they are facing away from each other. If it is 0, they are perpendicular

So if the dot product is:

  • DotValue > 0.95, they are facing the same direction

  • DotValue < -0.95, they are facing away

  • abs(DotValue) < 0.05, they are perpendicular

An important thing to note is before the dot product is done, the two vectors need to be normalized

more ▼

answered Oct 23 '18 at 11:06 AM

avatar image

Ali Akbar
691 2 6 8

avatar image Detilium Oct 23 '18 at 03:23 PM

Using the dot product actually solved my problem. Thank you for your answer.

In case someone was wondering, it's possible to get the dot product from an FVector like this: float DotProduct = FVector().DotProduct(FVector A, FVector B). Reference from the docs

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

One thing you can do is the following:

  • Analyze Component by Component. Compare the two vectors (X, Y, Z) and get in which ones the Axis > 0 (and/or = 1).

  • Save each configuration in a variable (per say, an int array). In an example, Array of Actor 1 = 0, 0, 1, Actor 2 = 1, 0, 0.

  • Compare values on the items individually. The result, therefore, determines if they're facing each other. in the example above, Array check loop would return in all of them being inconsistent, so they're not facing.

more ▼

answered Oct 23 '18 at 12:31 AM

avatar image

me4dinosaur
277 15 18 21

(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