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"

How to get an angle between 2 Vectors in Local Coordinates?

Hi community :) What i want to do is dashing Actor2 around Actor1 when i targeted on him like in Dark Souls. I already did the dash and round moving of actor but it always start moving around from 0° degree that mean left side of actor thats why i need know angle between Actor1 and Actor 2 in Local Coordinates not in World Coordinates. Does anyone know the right formula? I will appreciate any format c++ or blueprints

alt text

Product Version: UE 4.19
question1.png (68.5 kB)
more ▼

asked Jan 22 '19 at 12:40 PM in Blueprint Scripting

avatar image

1 1 4

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

2 answers: sort voted first

Here function that i wanted in blueprint, not perfect actually because it rotates world axis and not around local actor axis but it works for me now. Here screenshots of function below

screenshot-10.png (221.3 kB)
screenshot-11.png (369.3 kB)
screenshot-12.png (207.0 kB)
more ▼

answered Jan 30 '19 at 02:18 PM

avatar image

1 1 4

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

I put this in a function library, so it can be used on either C++ or BP. It's standard Vector Math, so I didn't "invent" it, merely turned it into a UE4 format.

 float UYourFunctionLib::AngleBetweenTwoVectors( FVector VectorA, FVector VectorB )
     // Angle between two vectors:
     // Angle = ArcCosine( ( vectorA dot VectorB ) / ( VectorLengthA x VectorLengthB ) )
     float angle = 0;
     // Dot Product
     float dotProduct = FVector::DotProduct( VectorA, VectorB );
     float lengthProduct = VectorA.Size() * VectorB.Size();
     // Angle
     angle = FMath::Acos( dotProduct / lengthProduct );
     return angle;

Simply pass any two vectors. You could take ActorA and Bs Position/Location, or their ForwardVector or RightVector.

With regards to converting from World to Local, there's another question here, with some answers. The key is to use Transform Location and/or Inverse Transform Location.

more ▼

answered Jan 22 '19 at 01:13 PM

avatar image

361 2 4 6

avatar image SiDiAndPERDi Jan 30 '19 at 01:51 PM

Thank you Jawdy to point me to the right direction, here your code in blueprint if someone wants alt text

screenshot-9.png (199.4 kB)
(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