How to set Yaw and Pitch for a Unit

rover2341

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


About
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?

325px-Flight_dynamics_with_text.png


Yaw
Ayaw.gif

Pitch
Aptch.gif

Roll
Aileron_roll.gif


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

1. Download Magos' Model Editor here
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"
6. Rename it into "Bone_Head"
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 = 'Trac'

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,"head", 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: 451

rover2341

Is riding a roller coaster...Wee!
Reaction score
114
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.
 

_whelp

New Member
Reaction score
54
@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 = 'Trac'

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)

call SetUnitLookAt(myUnit,"head", myUnit,pitchCos * yawCos,pitchCos*yawSin,pitchSin)

//Ignore the BJ's, I'm lazy.
 

rover2341

Is riding a roller coaster...Wee!
Reaction score
114
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.

About the roll
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
Reaction score
197
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!
Reaction score
114
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
Reaction score
197
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!
Reaction score
114
Note. I currently cant get this to work if the units y isnt zero. Not sure why...
 

rover2341

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

rover2341

Is riding a roller coaster...Wee!
Reaction score
114
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.
 

Viikuna

No Marlo no game.
Reaction score
265
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 SetUnitLookAt(.elevu,"bone_Head",.elevu,elevnose.x*100.,elevnose.y*100.,elevnose.z*100.)
            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!
Reaction score
114
Extremely Cool Video on hes map. WoW I am impressed. thanks for the good info.
 

rover2341

Is riding a roller coaster...Wee!
Reaction score
114
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.

Does that answer your question?

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 ! ---
Reaction score
157
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.

      The Helper Discord

      Staff online

      • Ghan
        Administrator - Servers are fun

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top