Sniper's Paradise!
Rotators
Rotators...what the hell are they? Think angles. But instead of 360 degrees you have 65535 UU's (unreal units). Every actor has a 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...try leaning over forwards, that would be consider pitching down), Yaw (think left/right...do a 360 spin...you just yawed), and finally Roll (think roll...er do a somersault, thats a form of roll). 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? Now, say you want to convert between vectors and rotators, or vice versa:
function ConvertMyRotatorsAndVectors() { local rotator myRot; // A rotator local vector myVec; // A vector
myVec = vect(0,0,0); // Lets set the vector to 0,0,0 myRot = Rotation; // then let myRot equal our current rotation myVec = 500 * vector(myRot); // Can you guess which direction myVec is pointing? }
If you guessed that myVec is pointing in the direction of Rotation, you're absolutely correct. Now lets suppose we added another line:
... myRot = rotator(myVec); // Where does myRot point now? ...
Now myRot will point in the direction myVec was pointing, which happened to be the direction myRot was pointing...whoa, thats almost paradoxical or something. :) I hope I'm not confusing you here... 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...
All logos and trademarks are properties of their respective owners.
Unreal™ is a registered trademark of Epic Games Inc.
Privacy Policy
Website by Softly
Powered by RUSH