Vectors and Rotators


 

This tutorial is rather simple, but important. Vectors and Rotators are vital to the understanding of how items are spawned in UT. This tutorial only attempts to define vectors and rotators as viewed by the spawn function. It may not be accurate in all instances not related to the spawn function, so please keep that in mind.

Since we are going to be looking at vectors and rotators in relation to the spawn function, let's first get a rundown of that function. The prototype is this:

native(278) final function actor Spawn

(



class<actor> SpawnClass,

optional actor SpawnOwner,

optional name SpawnTag,

optional vector SpawnLocation,

optional rotator SpawnRotation



);



When I first looked at the above, it confused the heck out of me, so let me explain it.

The SpawnClass variable is what you want to be spawned, i.e. a Rocket from a rocket launcher or a grenade from a grenade launcher. This is the only parameter that is required. In your code, it will look like this:

spawn(class'yourPack.yourItem');



The SpawnOwner variable is the person who the item is spawned from. Thus, if a player shot a rocket, the rocket's owner could be placed in the SpawnOwner spot. This variable is optional, and most people don't need it. Code:

spawn(class'yourPack.yourItem', yourSpawnOwner);



The SpawnTag variable is confusing even now, and I'm not sure what exactly it does yet.

SpawnLocation is where the item is spawned at in the level. It is a vector, and we will look at it in more detail later. Code:

spawn(class'yourPack.yourItem', yourSpawnOwner,,yourSpawnLocation);



If you noticed, you will see that there are two commas after yourSpawnOwner in the code above. The reason for that is that in order to bypass the SpawnTag variable, you have to include an extra comma to tell UT that yourSpawnLocation is associated with the SpawnLocation variable, and not the SpawnTag variable. I know that sounds confusing, so here is another example:

spawn(class'yourPack.yourItem',,,yourSpawnLocation);



Here, both the SpawnOwner variable and the SpawnTag variable are skipped, thus the extra two commas. I hope this makes it clear to you.

Finally, on to the last variable, SpawnRotation. This is a rotator, and we will also look at this in more detail. First, the code:

spawn(class'yourPack.yourItem',,, yourSpawnLocation, yourSpawnRotator);



I've gone ahead and done away with the yourSpawnOwner variable, as it is hardly used, but you may find a use for it.

Vector Variable SpawnLocation in more detail:

SpawnLocation is where in the level your item will be spawned. It is a vector, and every vector has 3 parts: an X, a Y, and a Z component. The X, Y, and Z of the vector makes up a 3d point in a UT level that the object you spawn appears at. Usually, this is the same location as the actor that spawns the object. Every actor in a level has a default property called Location. To access that point, you would write something like this:

local pawn yourPawn;

local vector spawnLoc;



spawnLoc = yourPawn.Location;



In this code, spawnLoc is set to the point in the level where yourPawn is. Of course this is very simplified code, but you get the idea.

There are a few ways to change the variables contained in a vector. The easiest (but longest) way is to change the individual components individually. Basically:

spawnLoc.X += 3;

spawnLoc.Y += 4;

spawnLoc.Z += 5;



The other way is to change the vector by using another vector:

local vector addVect;



spawnLoc += addVect;



Of course, addVect has to be initialed first, but you get the idea.

You must be careful about just assigning a vector arbitrary values, because you can never be sure where the vector is in the level. If you set a vector in your code to be (0,0,0), then anything spawned using that vector will spawn at (0,0,0)...however, that point may be in the middle of a rock in one level, or right at a team's flag, or whatever. Therefore, most vectors should be used in relation to a point that you can know. Such as taking a player's Location variable, assigning another vector that location, and then modifing the new vector to do what you want.

The final thing is an explaination of the various components of the vector. The X portion of it is the horizontal part. The Y portion is up and down, and the Z portion is horizontal as well, perpendicular to the X component.

Rotator Variable SpawnRotation in more detail:

SpawnRotation defines the direction that your spawned item will travel if it does travel. In fact, the only reason you will need a SpawnRotation is to define the direction that an object will travel, or the direction your object will face (although I'm not sure about the last one). Every rotator has 3 parts: a pitch, a yaw, and a roll. Every actor in UT has a default property called Rotation, which is accessed exactly like the Location variable in the sample code above.

A rotator can also be changed by the same methods as a vector. The only difference is the properties involved:

local rotator newRot;



newRot.Yaw += 3;

newRot.Pitch += 4;

newRot.Roll += 5;



A rotator can be assigned arbitrary values, and a certain value means a certain thing. The Yaw component is used to define the horizontal aspect of the rotator. A full circle is 65,535. You may define a Yaw component higher than 65535, but that will just begin to overlap the same circle that has already been used. For example, if you wanted an object to spin around 2 times, the final value of the Yaw component will be 131070. You can also define negative values, and that is like going around the circle in reverse.

Pitch is the vertical aspect of the rotator. A value of 0 is horizontal. Anything up to 32767 is like the equivalent of 0 to 89 degrees. A value of 32767 is straight up, and anything over 32767 is the equivalent of 91-180 degrees (i.e. the projectile will go backwards). A negative value will make the projectile go down instead of up. Also, anything over 65535 will make the projectile go down as well, until the value passes 131070, and so on and so forth.

Roll I don't really understand yet (I've never used it), but I think it is used to make your projectile spin.

All of the values I've listed above I got from trial and error in coding. They may not be 100% correct, but they are very close.