- Unreal Development Kit Game Programming with UnrealScript:Beginner's Guide
- Rachel Cordone
- 432字
- 2021-08-27 11:59:07
Time for action – Using rotators
Before we use rotators on our AwesomeActor
, we need to add some visual clue to let us know that it's actually rotating. To do that we're going to add another bit to our default properties like the sprite, but this time it will be an arrow we'll be able to see in the editor.
- Below the sprite in the default properties, add this:
Begin Object Class=ArrowComponent Name=Arrow End Object Components.Add(Arrow)
- We're going to log our actor's current rotation, so inside our
PostBeginPlay
add this:'log("Rotation:" @ Rotation);
Our class should now look like this:
class AwesomeActor extends Actor placeable; function PostBeginPlay() { 'log("Rotation:" @ Rotation); } defaultproperties { Begin Object Class=SpriteComponent Name=Sprite Sprite=Texture2D'EditorResources.S_NavP' End Object Components.Add(Sprite) Begin Object Class=ArrowComponent Name=Arrow End Object Components.Add(Arrow) }
- Compile and take a look in the editor. Our actor now has an arrow to indicate its current rotation.
- By default we know its current rotation is going to be (0,0,0), so let's rotate it in the editor. Click on the
AwesomeActor
to select it, and then press the Space bar once to change to the rotation tool. - Now click and hold anywhere on the blue part of the rotation tool. We're going to change our actor's Yaw, so move it as close to 90 degrees as you can get. Don't worry if it's not perfect.
- Save our map, and then run it in the game. Exit and check the log for our rotation value.
[0008.33] ScriptLog: Rotation: 0,16160,0
It's logging, but why is the value so high? That's definitely not 90. Internally, the ints that make up rotators are 32 bits and have a range of 0 to 65535. Therefore, in Unreal's unit system, 360 degrees = 65536. That would make 90 degrees = 16384, which is close to what was logged.
Rotators can be created the same as we did with vectors. You can make a var like this:
var rotator MyRot;
And then change the individual components in the PostBeginPlay
function.
MyRot.Yaw = 2000;
You could also create a rotator as it's being used, like we did with vectors. The names of the functions we use for this are specific to rotators though:
SetRotation(Rotation + rot(0,0,4000));
What just happened?
Rotators, like vectors, are important structs to be examined on their own. Every actor in the game has a rotation, and the most noticeable use of rotators is in the player's camera, to tell the game where we're looking.
We've talked a lot about variables in this chapter. Next we're going to discuss ways we can change how they work.
- ATmega16單片機項目驅(qū)動教程
- 龍芯應(yīng)用開發(fā)標準教程
- Effective STL中文版:50條有效使用STL的經(jīng)驗(雙色)
- 深入淺出SSD:固態(tài)存儲核心技術(shù)、原理與實戰(zhàn)
- 單片機原理及應(yīng)用系統(tǒng)設(shè)計
- 計算機組裝與維修技術(shù)
- Visual Media Processing Using Matlab Beginner's Guide
- Building 3D Models with modo 701
- 筆記本電腦維修300問
- 電腦橫機使用與維修
- FreeSWITCH Cookbook
- 微服務(wù)實戰(zhàn)
- 計算機組裝、維護與維修項目教程
- 筆記本電腦現(xiàn)場維修實錄
- 計算機組裝與維護