| Home Page | Recent Changes | Preferences

Rotator

Copied and modified from a [CHiMERiC] tutorial (http://chimeric.beyondunreal.com/tutorials/rotators.html .)

Includes [Jeremy T's info] about loss of roll when converting to a vector.

Rotators are one of the Built-In Structs. But what the hell are they? Think angles. But instead of 360 degrees, a full circle is 65535 UUs (unreal units). Every Actor has a Movement → Rotation variable that determines (gasp) what direction the actor is pointing. Heres exactly what a rotator is:

 struct Rotator
 {
    var() config int Pitch, Yaw, Roll;
 };

Rotators have 3 parts:

  • Pitch (think up/down...like nodding your head "yes")
  • Yaw (think left/right...like shaking your head "no")
  • Roll (tilt your head to one side, so you're still looking the same direction, but one ear is pointing up and the other down).

You can modify the angles just by changing each of the values, but you can not modify an actor's rotation directly, you must use the SetRotation(newRotation) function, as shown below.

 function ChangeRotation()
 {
    local Rotator newRot;    // This will be our new Rotation
    newRot = Rotation;       // Set newRot to our current Rotation
    newRot.Pitch += 32768;   // Since 65535 = 360, half of that equals 180, right?
    newRot.Yaw -= 16384;     // And half of that equals 90 and so on...
    SetRotation(newRot);     // After we've done our tweaking go ahead and set the new rotation
 }

So what did we just do? We made something pitch 32768 UU's (180 degrees), and then turn 16384 UU's (90 degrees). Make sense? To get a vector of length one that points in the direction of the rotator:

   local rotator myRot;
   local vector myVec;
   ...
   myVec = vector(myRot);
   ...

Always remember: the "roll" angle would rotate a vector about it's own axis. But a vector is a mathematical line, if you do that it doesn't change at all. Therefore, myVec in the example above doesn't have any roll information. There's no way to figure out the roll component of myRot by looking at myVec. See also Typecasting.

To get a rotator that corresponds to a vector, type:

   ...
   myRot = rotator(myVec);
   ...

Since vectors don't have roll information, the "roll" of myRot will be zero, but the other parts will be correct.

Say you wanted myRot to point 90 degrees to the left...lets add another line:

   ...
   myRot.Yaw += 16384;      // Now myRot points 90 degrees to the left of before
   ...

Easy stuff no? Just remember 65535 = 360 degrees, and to use SetRotation, and you'll do good. Rotators are useful for using angle based math, in many cases can be used in place of vector math to make some tasks much simpler. Thankfully Unreal already handles converting back and forth...

Musicalglass: OK, that will make it so when you open your map, it will be rotated in a new static position. Now how do you introduce the element of time into the equation? Like have your object start at zero and rotate to the new settings over a period of say, 10 seconds?

I know there are several different interpolation functions available as well, like linear and smooth. Could somebody please add a couple of simple equations to this page which show you how to do this? Thanks

Foxpaw: I think this page is more about rotators themselves, not about actor rotation but I suppose some iterpolation stuff could go here. You should be able to accomplish what you want by setting bRotateToDesired true, then setting a desiredrotation and a rotationrate, as well as a physics type that supports this type of rotation. Then the object will start rotating toward the angle in desiredrotation at the rate specified in rotationrate.

Functions

The following Global Function apply to rotators.

GetAxes (rotator A, out vector X, out vector Y, out vector Z) [static]
Returns the three vectors X, Y and Z, where X is forward direction, Y points right and Z points upwards. (relative to the rotation expressed by A)
GetUnAxes (rotator A, out vector X, out vector Y, out vector Z) [static]
If you think of X, Y and Z as 3x3 matrix, GetUnAxes returns the Wikipedia logo transposed matrix relative to what GetAxes would return with the same rotator.

Foxpaw: This explains the out variables, but what IS it? The X, Y and Z return the matrix relative to what GetAxes would return - this implies that this returns something different? I don't understand what this function does, only that it's output is a 3x3 matrix?

rotator RotRand (optional bool bRoll) [static]
Returns a random rotator. If bRoll is False the Roll component of the rotator is 0.
rotator OrthoRotation (vector X, vector Y, vector Z) [static]
Returns a rotator from three Wikipedia logo orthogonal vectors.
rotator Normalize (rotator Rot) [static]
Returns the corresponding rotator with components between -32768 and 32768.

Operators

See Operators

Related Topics

(there's a table of URU to degrees on both those pages)

The Unreal Engine Documentation Site

Wiki Community

Topic Categories

Image Uploads

Random Page

Recent Changes

Offline Wiki

Unreal Engine

Console Commands

Terminology

Mapping Topics

Mapping Lessons

UnrealEd Interface

Questions&Answers

Scripting Topics

Scripting Lessons

Making Mods

Class Tree

Questions&Answers

Modeling Topics

Questions&Answers

Log In