# How to set Yaw and Pitch for a Unit

#### rover2341

##### Is riding a roller coaster...Wee!
How to set Yaw and Pitch for a Unit

What this tutorial shows you how to do, is how to change a unit with a model
that has had a tweak done to it,be able to change the yaw and pitch with code.

Note: I currently have Yaw and Pitch. Ill add how to do roll also at some point in the future (1 - 3 weeks).

Note: It Currently Flips the model after 90 degrees and 270 degrees. Making it look werid for my roller coaster project.

What are Yaw, pitch, and roll?

Yaw

Pitch

Roll

How To set Just Yaw and Pitch
There are 3 steps.

The first step is to setup the model.
The second step is to create a unit, and two variables called "Yaw" and "Pitch".
The third step is to set the yaw and pitch in the code.

Step 1

2. Open the model in Magos
3. Select "Windows -> Node Manager"
4. Right-click the helper (Balloon with an "i" inside) called "Bone_Root" or similar
5. Select "Edit Node"
7. Save
8. Import into map

Step 2

1.Setup the model type (this is the value that repesents your custom model)
2.Change "Art - Animation - Blend Time (seconds)" to 0 seconds.
3.Create a Unit
4.Create two real variables that have a number that is a degree.

JASS:
``````
//Trac is just for my custom model yours is likely difffernt
local integer myUnitType = &#039;Trac&#039;

local unit myUnit = CreateUnit(Player(0),myUnitType,0,0,0)

local real yaw = 90
local real pitch = 90

if ( pitch == 90.0 ) then
set pitch = 89
endif

if ( pitch == 270.0 ) then
set pitch = 269
endif``````

Step 3

1. Set Yaw and Pitch for unit.

JASS:
``call SetUnitLookAt(myUnit,&quot;head&quot;, myUnit,CosBJ(pitch)*CosBJ(yaw)*1000000.,CosBJ(pitch)*SinBJ(yaw)*1000000.,SinBJ(pitch)*1000000.)``

The Attached Map is in vJass

Credits
grim001 - Found a similar tutorial made by him, Added the 1000000 that fixed it.
KaTTaNa - Did the part that said you cant be 90 for pitch.
Michael Peppers - Step 1
uberfoop - Step 3
Viikuna - Step 1
Rover2341 - Step 2 and put them all together in this thread.

#### Attachments

• SetYawAndPitch v3.w3x
18.6 KB · Views: 467

#### Grundy

##### Ultra Cool Member
Wouldn't yaw just be SetUnitFacing(yourUnit, someAngle)

#### rover2341

##### Is riding a roller coaster...Wee!
Correct, But when doing both at the same time. I am pretty sure you have to do it this way. There is one other way, but I am going to use that to set the roll, I am just not that far yet.

#### Tom_Kazansky

##### --- wraith it ! ---
please make the "roll", the model's gonna have 3D rotation, cool !

#### _whelp

##### New Member
@Step 2 and 3:

You could just make Cos and Sin in your variables instead of calling them multiple times...

Ex:

JASS:
``````//Trac is just for my custom model yours is likely difffernt
local integer myUnitType = &#039;Trac&#039;

local unit myUnit = CreateUnit(Player(0),myUnitType,0,0,0)

local real yawCos = CosBJ(90)
local real pitchCos = CosBJ(90
local real yawSin = SinBJ(90)
local real pitchSin = SinBJ(90)

//Ignore the BJ&#039;s, I&#039;m lazy.``````

#### rover2341

##### Is riding a roller coaster...Wee!
Tom_Kazansky
Its possible with code as well, I just don't have the modeling skills quite yet.
I don't think its a huge task though.

_whelp
That's true but I like to work with things in degrees personally. My Roller coaster game is designed that way at least so the way I currently have it setup is better for me.

For Roll, I know I can do it with many animation IDs, with the roll different. But I don't have the modeling skills to do this yet. Someone else used to to change the Pitch, But I am quite sure it can be used for the roll. It can be changed in code as well.

If anyone wants to help me on this, I can show them all the information I have on It. Just Replay here about it or pm me.

#### HydraRancher

##### Truth begins in lies
Looks great, now transitions between different angles will be much smoother, when will you be implementing this in Roller Coaster?

#### rover2341

##### Is riding a roller coaster...Wee!
I restarted building it in vJass a few weeks ago. I started to put in in yesterday. But my vJass version of roller coaster will still be a few weeks.

I dont think anyone will be able to tell the difference for roller coaster form my gui to vJass (aside from the models connecting smoother).

#### HydraRancher

##### Truth begins in lies
I restarted building it in vJass a few weeks ago. I started to put in in yesterday. But my vJass version of roller coaster will still be a few weeks.

I dont think anyone will be able to tell the difference for roller coaster form my gui to vJass (aside from the models connecting smoother).

The very reason why this thread caught my eye was because you're Rover! And you can do anything (except this!) including your fascinating Tetris game.

#### rover2341

##### Is riding a roller coaster...Wee!
Note. I currently cant get this to work if the units y isnt zero. Not sure why...

#### GetTriggerUnit-

##### DogEntrepreneur
Maybe because it does not have the ability 'Crow' || 'Armf'.

This system would need AutoFly

#### rover2341

##### Is riding a roller coaster...Wee!
Updated, It works fully now except that it flips the model so the sprayed on shadow looks weird. As gos beyound 90 and 270.

#### D.V.D

##### Make a wish
Cool but is it possible to set Roll with code to?

#### rover2341

##### Is riding a roller coaster...Wee!
Ya I just haven't got that fair, If you don't feel like waiting for me its at the wc3c.net. But I haven't got that far yet.

#### D.V.D

##### Make a wish
Ok thanks Im probably gonna end up using this. Thank +rep

#### Viikuna

##### No Marlo no game.
You could indeed make some dummy model with roll animations and use SetUnitLookAt for pitch and yaw. This has already been done:

Bob666, or N-a-z-g-u-l, or whatever his name is, has already done this one flight simulator thingy where planes have pitch, yaw and roll rotations. ( Can be found from here )

If you open that map you can see that he uses SetUnitPosition, which somehow counters these problems:

JASS:
``````            call SetUnitAnimationByIndex(.elevu, R2I(ModuloReal(elevr*bj_RADTODEG*0.7+.5,252)))
call SetUnitFlyHeight(.elevu,.pos.z+elevPos.z-elevterrZ,0)
call SetUnitPosition(.elevu,.pos.x+elevPos.x,.pos.y+elevPos.y)``````

Here is the original thread where he solved this lil problem: link

Anyways. I have also myself experienced with locking units facing to another invisible dummy unit by calling SetUnitLookAt only once on map init, and then modifying facing angle by moving that dummy. It works usually pretty nicely, but has some weird problems sometimes. Dont know if they are model related, or some buggs with SetUnitlookAt, sbecause I never bothered to do enough research.

#### rover2341

##### Is riding a roller coaster...Wee!
Extremely Cool Video on hes map. WoW I am impressed. thanks for the good info.

#### D.V.D

##### Make a wish
Ya I just haven't got that fair, If you don't feel like waiting for me its at the wc3c.net. But I haven't got that far yet.

I haven't been able to find how to set Yaw so could you please link it?

#### rover2341

##### Is riding a roller coaster...Wee!
What I currently Have does yaw and pitch. You can mess with it to do Pitch and roll instead.

If you want all 3 the post above from "Viikuna" Is how to do them all.
I do want to make it straight forward how to do it as soon as i understand it.

Can you show me what you have, If you cant get it to do the Yaw for you. Yaw is just the direction the unit is looking.

#### Tom_Kazansky

##### --- wraith it ! ---
is it just me or the model (with special effect attached to it) acts weird when I call "SetUnitLookAt" too fast ? ( erm... I call "SetUnitLookAt" every 0.04s )

General chit-chat
Help Users
• No one is chatting at the moment.

### Members online

No members online now.