How to set Yaw and Pitch

rover2341

Is riding a roller coaster...Wee!
Reaction score
113
About
I am trying to figure out how to use SetUnitLookAt to set my Yaw and pitch.
I changed my model like the quote said, and I can make my model angle at another unit. But I cant figure out how to set the Yaw and Pitch to what i want, with only 1 unit.

You use dummy which has its main bone named "head" and then rotate it with SetUnitLookAt

What I Did
I changed the name of bone_head and it worked.

What Works
Now With 2 units I can have one look at the other at the with yaw and pitch.

What I still Need
I want 1 Unit to be set at yaw and pitch. (x = pitch) (y = yaw)
I understand how to work with "SetUnitLookAt"

Code
Code is done in vJass.

JASS:
library SetupGame initializer InitA

    function environment takes nothing returns nothing
        call SetSkyModel( "Environment\\Sky\\LordaeronSummerSky\\LordaeronSummerSky.mdl" )
        call FogEnableOff(  )
        call FogMaskEnableOff(  )
        call UseTimeOfDayBJ( false )
        call SetTimeOfDay( 12 )
    endfunction

    
    function createUnitWithYawAndPitch takes nothing returns nothing
    
        local integer myUnitType = 'Trac'
        local unit myUnit
        local unit myUnit2
        
        set myUnit = CreateUnit(Player(0),myUnitType,200,200,90) 
        set myUnit2 = CreateUnit(Player(0),myUnitType,0,0,90) 
        call SetUnitFlyHeight(myUnit,400,0)
        call SetUnitLookAt(myUnit,"head", myUnit2, 0,0,0)

    endfunction  

//===========================================================================
    function InitA takes nothing returns nothing
        
        call createUnitWithYawAndPitch()
        call environment()
        
    endfunction
     
endlibrary
 

Attachments

  • SetYawAndPitch v2.w3x
    19.2 KB · Views: 293

rover2341

Is riding a roller coaster...Wee!
Reaction score
113
Bump.

If anyone could give me any information on if this is possible or not, or how to do it would be great. Thanks :)
 

rover2341

Is riding a roller coaster...Wee!
Reaction score
113
I updated the first post, with new info, I am a few steps farther then i was before. I just need help figuring out how to work it now.
 

uberfoop

~=Admiral Stukov=~
Reaction score
177
Tell the unit to look at itself, and use the 3 offsets to get yaw and pitch. I am assuming that theta is measured via the standard method of counterclockwise from 0, and phi is measured as the angle up from the horizon. Because that's how I do math.

Anyhow:

Yaw:
x = Cos(pitch)*Cos(yaw)
y = Cos(pitch)*Sin(yaw)

Pitch:
z = Sin(pitch)


So basically:
[ljass]call SetUnitLookAt(myUnit,"head", myUnit,Cos(pitch)*Cos(yaw),Cos(pitch)*Sin(yaw),Sin(pitch))[/ljass]

Note that I didn't actually test this, but its math seems to check out. It should work as long as wc3 doesn't take issue with small distances, at which point you could probably fix it by multiplying each of those 3 new values by 1000 or something.

This is accomplished mathmatically by assuming a unit vector points, in spherical coordinates, as <1,yaw,pitch>, and solving for the side lengths.
 

rover2341

Is riding a roller coaster...Wee!
Reaction score
113
Ill Give it a shot. Ill update this post, after I try it out. Thanks


Edit*
It Works, I had issues at first because I was sending in degrees when it wanted radians but I fixed that. Thanks alot.

Here is updated code
JASS:
library SetupGame initializer InitA

    function environment takes nothing returns nothing
        call SetSkyModel( &quot;Environment\\Sky\\LordaeronSummerSky\\LordaeronSummerSky.mdl&quot; )
        call FogEnableOff(  )
        call FogMaskEnableOff(  )
        call UseTimeOfDayBJ( false )
        call SetTimeOfDay( 12 )
    endfunction

    
    function createUnitWithYawAndPitch takes nothing returns nothing
    
        local integer myUnitType = &#039;Trac&#039;
        local unit myUnit

        local real yaw = 90
        local real pitch = 90
        
        set myUnit = CreateUnit(Player(0),myUnitType,0,0,0) 

        call SetUnitFlyHeight(myUnit,400,0)
        call SetUnitLookAt(myUnit,&quot;head&quot;, myUnit,CosBJ(pitch)*CosBJ(yaw),CosBJ(pitch)*SinBJ(yaw),SinBJ(pitch))

    endfunction  

//===========================================================================
    function InitA takes nothing returns nothing
        
        call createUnitWithYawAndPitch()
        call environment()
        
    endfunction
     
endlibrary
 

saw792

Is known to say things. That is all.
Reaction score
280
>[ljass]not false[/ljass]

Ahem... [ljass]true[/ljass]
 

Narks

Vastly intelligent whale-like being from the stars
Reaction score
90
[LJASS]not not true[/LJASS]

I wonder if that compiles...
 

rover2341

Is riding a roller coaster...Wee!
Reaction score
113
apparently this doesn't work if the unit is at 0,0. I tried different spots and it wont show up.
 

Narks

Vastly intelligent whale-like being from the stars
Reaction score
90
I remember something about multiplying the values given to SetUnitLookAt by a million to offset some z-level error or something. It was on wc3c, if it comes back up I'll link the post.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      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