Vector to Rotator (C++)

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.

Shambler[sixpack]

New Member
May 3, 2001
564
0
0
Ireland
Visit site
Ok I've only just started coding stuff in C++ today...Can someone please (for the love of god) tell me how I can convert a vector into a rotator (FVector into FRotator) through C++??

I've looked all the way through UnMath.h and other public source files and I didn't find an answer..
 

Darknigh+

New Member
Oct 19, 2003
113
0
0
www.cis.usouthal.edu
[Sixpack]-Shambler- said:
Ok I've only just started coding stuff in C++ today...Can someone please (for the love of god) tell me how I can convert a vector into a rotator (FVector into FRotator) through C++??

I've looked all the way through UnMath.h and other public source files and I didn't find an answer..

I have only done this thing before when I was only consirended with the yaw and pitch. However you should be able to just add in the z component for the following if you need the roll.

For startes you will need the direction of the vector. This can be found by:

//use atan2 beceause there are cases when atan can return infinity.
//direction will be in radians
direction = atan2(v.y,v.x);

//you will also need the magnitude of the vector
magnitude = sqrt(v.x*v.x + v.y * v.y);

//here is where you would get your x and y componets of your rotator
//i.e your yaw and pitch.
yaw = magnitude * cos(direction);
pitch = magnitude * sin(direction);

Hope this helped
 

Winged Unicorn

From wishes to eternity
[Sixpack]-Shambler- said:
Can someone please (for the love of god) tell me how I can convert a vector into a rotator (FVector into FRotator) through C++??

Shambler, assuming that:

  • myVector is the native FVector
  • myRotator is the native FRotator
  • you're using UnrealEngine1 headers

all you have to do is:

Code:
myRotator = myVector.Rotation();

There's also the other way round:

Code:
myVector = myRotator.Vector();

That's it ;)
 
Last edited: