How to set Yaw and Pitch for a Unit

rover2341

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

rover2341

Is riding a roller coaster...Wee!
Reaction score
113
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
113
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
113
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
113
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
113
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
113
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
113
Extremely Cool Video on hes map. WoW I am impressed. thanks for the good info.
 

rover2341

Is riding a roller coaster...Wee!
Reaction score
113
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.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top