How can you change a units "PITCH" After The Units Created?

Arkless

New Member
Reaction score
31
I Belive this might BE IT! The bottom one.

Starcraft 2 Has its Z/(x/y) Backwards from what we thought.

Can you check If this is right?! I think it is! :)

*scratches his head* this would make no real difference (first thought), it would just change the angle. Everything missing to do roll + pitch + yaw is the up-vektor wich I couldn't get to respond to any value I tested. No matter wich value I used, it always tried to be as close to 0/0/1 as possible with the given forward(mathematically out)-vector.
 

rover2341

Is riding a roller coaster...Wee!
Reaction score
114
Not sure then, Maybe it shouldnt work but it is for me.
I wanted to be sure so I messed around with it for about in hour.

Can you test the map and tell me if it works for you?

I use moonlight but this is my full code
Code:
////////////////////////////////////////////////////
// Title: Changing a units yaw and pitch demo     //
// Version: 1.0                                   //
//                                                //
//                                                //
// Notes: If a unit, turns upside down at any     //
//        point it will roll 180 Degrees. Ground  //
//        units dont seem to work right even if   //
//        you make them float.                    //
//                                                //
////////////////////////////////////////////////////
// Trigger Variables                              //
////////////////////////////////////////////////////
trigger AfterInit;
trigger Spin;

////////////////////////////////////////////////////
// Varibles                                       //
////////////////////////////////////////////////////
unit aUnit = null;
fixed pitchG = 0;
fixed yawG = 0;

////////////////////////////////////////////////////
// First Fuction To Run                           //
////////////////////////////////////////////////////
static
{     
    AtInit();   
}

////////////////////////////////////////////////////
// At Init                                        //
////////////////////////////////////////////////////
void AtInit()
{ 
    
    libNtve_gf_CreateUnitsAtPoint2(1, "VoidRay", 0, 1, RegionGetCenter(RegionPlayableMap()));
    UnitSetHeight(UnitLastCreated(), 3, 0.0);
    aUnit = UnitLastCreated();            

    AfterInit_Init();
    Spin_Init();
}

////////////////////////////////////////////////////
// After Init                                     //
////////////////////////////////////////////////////
bool AfterInit_Func (bool testConds, bool runActions) 
{
    // Actions
    if (!runActions) 
    {
        return true;
    }
    
    ChangePitch(aUnit, 0);
    return true;
}

void AfterInit_Init()
{
    AfterInit = TriggerCreate("AfterInit_Func");
    TriggerAddEventTimeElapsed(AfterInit, 1.0, c_timeGame);
}

////////////////////////////////////////////////////
// Spin (Periodic Timer)                          //
////////////////////////////////////////////////////
bool Spin_Func (bool testConds, bool runActions)
{
    pitchG = pitchG + 1;
    yawG = yawG + 1;
    
    ChangeOrientation(aUnit, yawG, pitchG);
//    ChangePitch(aUnit, pitchG);
    return true;
}

void Spin_Init ()
{
    Spin = TriggerCreate("Spin_Func");
    TriggerAddEventTimePeriodic(Spin, .001, c_timeGame);
}

////////////////////////////////////////////////////
// ChangePitch                                    //
////////////////////////////////////////////////////
void ChangePitch(unit target, fixed pitch)
{
    
    TriggerDebugOutput(1, StringToText("Pitch: " + pitch), true);
    TriggerDebugOutput(1, StringToText(" "), true);    
    
    // Variable Declarations
    fixed yaw;
    fixed forwardX;
    fixed forwardY;
    fixed forwardZ;
    fixed upX;
    fixed upY;
    fixed upZ;

    // Variable Initialization
    yaw = UnitGetFacing(target);  
    forwardX = Cos(yaw) * Sin(pitch);
    forwardY = Sin(yaw) * Sin(pitch);
    forwardZ = Cos(pitch);
    upX = 0;
    upY = 0;
    upZ = 0;
    
    // Implementation
    libNtve_gf_SendActorMessageToUnit(target, libNtve_gf_SetRotation(forwardX, forwardY, forwardZ, upX, upY, upZ));
    
}

////////////////////////////////////////////////////
// ChangeOrientation                              //
////////////////////////////////////////////////////
void ChangeOrientation (unit target, fixed yaw, fixed pitch) 
{    
    TriggerDebugOutput(1, StringToText(" "), true);    
    TriggerDebugOutput(1, StringToText(" "), true);    
    TriggerDebugOutput(1, StringToText(" "), true);    
    TriggerDebugOutput(1, StringToText(" "), true);    
    TriggerDebugOutput(1, StringToText(" "), true);    
    TriggerDebugOutput(1, StringToText(" "), true);    
    TriggerDebugOutput(1, StringToText(" "), true);    
    TriggerDebugOutput(1, StringToText(" "), true);    
    TriggerDebugOutput(1, StringToText(" "), true);    
    TriggerDebugOutput(1, StringToText(" "), true);    
    TriggerDebugOutput(1, StringToText(" "), true);    
    TriggerDebugOutput(1, StringToText(" "), true);     
    TriggerDebugOutput(1, StringToText(" "), true);    
    TriggerDebugOutput(1, StringToText(" "), true);    
    TriggerDebugOutput(1, StringToText(" "), true);    
    TriggerDebugOutput(1, StringToText(" "), true);    
    TriggerDebugOutput(1, StringToText(" "), true);    
    TriggerDebugOutput(1, StringToText(" "), true);    
    TriggerDebugOutput(1, StringToText(" "), true);    
    TriggerDebugOutput(1, StringToText(" "), true);    
    TriggerDebugOutput(1, StringToText(" "), true);    
    TriggerDebugOutput(1, StringToText(" "), true);    
    TriggerDebugOutput(1, StringToText(" "), true);    
    TriggerDebugOutput(1, StringToText(" "), true);    
    TriggerDebugOutput(1, StringToText(" "), true);    
    TriggerDebugOutput(1, StringToText(" "), true);    
    TriggerDebugOutput(1, StringToText(" "), true);     
    TriggerDebugOutput(1, StringToText(" "), true);    
    TriggerDebugOutput(1, StringToText(" "), true);    
    TriggerDebugOutput(1, StringToText(" "), true);    
    TriggerDebugOutput(1, StringToText(" "), true);    
    TriggerDebugOutput(1, StringToText(" "), true);      
    TriggerDebugOutput(1, StringToText("Pitch: " + pitch + "   Yaw: " + yaw), true);
    
    // Variable Declarations
    fixed forwardX;
    fixed forwardY;
    fixed forwardZ;
    fixed upX;
    fixed upY;
    fixed upZ;

    // Variable Initialization    
    forwardX = Cos(yaw) * Sin(pitch);
    forwardY = Sin(yaw) * Sin(pitch);
    forwardZ = Cos(pitch);
    upX = 0;
    upY = 0;
    upZ = 0;
    
    // Implementation
    libNtve_gf_SendActorMessageToUnit(target, libNtve_gf_SetRotation(forwardX, forwardY, forwardZ, upX, upY, upZ));
}
 

Attachments

  • Create Unit And Change Pitch.zip
    7.1 KB · Views: 190

eXirrah

New Member
Reaction score
51
In the 3D Rotation article I read that the Forward and Up vectors must
be perpendicular.

So if you want to rotate the unit the vectors must rotate like I draw on
the image. The problem is with the math, I will try to create a function
that calculates it right later.

Model%20Rotation.jpg
 

Arkless

New Member
Reaction score
31
Not sure then, Maybe it shouldnt work but it is for me.
I wanted to be sure so I messed around with it for about in hour.

Can you test the map and tell me if it works for you?

I use moonlight but this is my full code
Maybe my understanding of english is just off. I thought the yaw rotation was influenced by the pitch rotation (translating words misleads sometimes :p).
Well, if this is what you wanted then it's fine ^^.


In the 3D Rotation article I read that the Forward and Up vectors must
be perpendicular.

So if you want to rotate the unit the vectors must rotate like I draw on
the image. The problem is with the math, I will try to create a function
that calculates it right later.

I already did that, you might or might not have noticed...
For pitch and yaw that would be (I thought about it yesterday, but this should be it):

out_X = Cos(yaw) * Cos(pitch)
out_y = Sin(yaw) * Cos(pitch)
out_z = sin(pitch)
up_x = Cos(yaw) * (-Sin(pitch))
up_y = Sin(yaw) * (-Sin(pitch))
up_z = Cos(pitch)


For starters just try easy stuff, like (ox=1) and (uz=-1). This "should" make the unit be upside down.
 

rover2341

Is riding a roller coaster...Wee!
Reaction score
114
Currently Working
X = Cos(rotation) * Sin(pitch)
y = Sin(rotation) * Sin(pitch)
z = Cos(pitch)

This lets me set the pitch and the yaw.
The issue is when a unit is about to go upside down it auto rolls 180 degrees.

Not Currently Working
1. The unit auto rolls when its going to be upside down. Thats a issue a major issue for my game. The cart would flip to the cart would either flip to the other side of the track go when it rolls, would be have the wrong side of the cart on the track.
2. Being able to set roll would be great. (doesn't have to work, for my means)

Is the math right, with what I have working?
No Idea if its even close, I just reversed your z/(xy) graph to a (xy)/z graph and it seemed to make it work.

I Made a new map that does this. Does what I say currently working work?

http://www.thehelper.net/forums/showthread.php?p=1287337#post1287337
 

Arkless

New Member
Reaction score
31
With this, I am getting the yaw and pitch to work even if it shouldn't be working, the roll flips 180 if the unit trys to go upside down though.
Yes, I misunderstood the meaning of "yaw", yaw works perfectly well. The problem with flipping by 180 degrees is because we cant use the up vector. It's always as close to 0/0/1 as possible, thus the top side of the model can never face the ground.

I gota run but Ill be back and see if i can understand whats up.
So with that map your not getting full rotation and full yaw. Right?
If you are then continuing is to fix the roll or, Is that map not working?
I am getting a full rotation (pitch and yaw), the problem is that we can't tell him to go upside down without the up vector.

I won't be testing around anymore, because as long as I cant use the up-vector, there isn't anymore I could do.
 

rover2341

Is riding a roller coaster...Wee!
Reaction score
114
Now I get it, K If I get any thing working with the up-vector ill let you know.

Thanks Man :)
 

eXirrah

New Member
Reaction score
51
The functions Set Rotation and Set Bearings are bugged.

Set Rotation - Cannot rotate the actor around the X axis (roll). weir
stuff happens when you rotate the actor by Z(yaw) or Y(pitch) and set
X (roll) <> 0, 180. It is as if the roll angle is not set to rotaiton around
the X Axis but split and added to the rotations around Z and Y axes.

With no proper rotation around X axis(roll) the model flip when it rotates
to 90, 270 degrees around Y axis (pitch) cannot be avoided.

I've uploaded a map with a function that calculates the Forward and Up
coordinates of the rotation vectors function properly from yaw, roll and
pitch angles, but I couldn't fix the bugs I explained above.

So basicly this is a pitch+yaw function, but if Blizzard fix the X rotation
(roll) then this function should be able to do pitch+yaw+roll.

Download poke.SC2Map.
 

Arkless

New Member
Reaction score
31
The functions Set Rotation and Set Bearings are bugged.

Set Rotation - Cannot rotate the actor around the X axis (roll). weir
stuff happens when you rotate the actor by Z(yaw) or Y(pitch) and set
X (roll) <> 0, 180. It is as if the roll angle is not set to rotaiton around
the X Axis but split and added to the rotations around Z and Y axes.

With no proper rotation around X axis(roll) the model flip when it rotates
to 90, 270 degrees around Y axis (pitch) cannot be avoided.

I've uploaded a map with a function that calculates the Forward and Up
coordinates of the rotation vectors function properly from yaw, roll and
pitch angles, but I couldn't fix the bugs I explained above.

So basicly this is a pitch+yaw function, but if Blizzard fix the X rotation
(roll) then this function should be able to do pitch+yaw+roll.

Download poke.SC2Map.

We got pitch and yaw to work fine already.
I still took a look at your map, when I saw the math stuff I thought it looks kinda... wrong. I tested it. I took another short look at your code.

Now I'm pretty sure you did something wrong, you are increasing the pitch value and call your function with. Said function changes pitch and yaw with only the pitch parameter changing. The pitch angle never goes past a certain point (up/down), even thought you are increasing it past 360 (wich should make it a full circle).
 

eXirrah

New Member
Reaction score
51
Sadly, you are right. This is a pitch+yaw function

I didn't do anything wrong man. I did what I draw on the image a few
posts back. The rotation matrix of rotation around an arbitrary axis is huge. I used
it to calculate the pitch because after changing the yaw and roll of the
model, changing its pitch is no longer rotating the vectors around the
world's Y axis, but around a local one for the model (I draw the local for
the model axes on the image in purple in step 4). I represent the new
axis by R vector and calculate the rotation matrix elements. The I
multiply the Forward and Up vectors by the matrix.

The rot_R coordinates contain the matrix elements. For example
rot_Rx.x=a11, rot_Ry.z = a23 ...
Try adding a roll angle to your function and the results will be the same.

The problem is that the Up vector coordinates cannot be changed.
It looks like the Up vector is hard coded to (0,0,1) and there is nothing
we can do to change that.

Unless Blizzard fix that my function works just as yours, I tested it
and it really does ... so I doubt that my calculations are wrong.

If you pass a roll angle value different than 0,180,360 ... then weird
stuff happens. The roll angle depends on the position of the Up vector,
that's why it doesn't work, so set the t_roll variable to 0 and the
function does change yaw+pitch properly.
 

Arkless

New Member
Reaction score
31
Sadly, you are right. This is a pitch+yaw function

I didn't do anything wrong man. I did what I draw on the image a few
posts back. The rotation matrix of rotation around an arbitrary axis is huge. I used
it to calculate the pitch because after changing the yaw and roll of the
model, changing its pitch is no longer rotating the vectors around the
world's Y axis, but around a local one for the model (I draw the local for
the model axes on the image in purple in step 4). I represent the new
axis by R vector and calculate the rotation matrix elements. The I
multiply the Forward and Up vectors by the matrix.

The rot_R coordinates contain the matrix elements. For example
rot_Rx.x=a11, rot_Ry.z = a23 ...
Try adding a roll angle to your function and the results will be the same.

The problem is that the Up vector coordinates cannot be changed.
It looks like the Up vector is hard coded to (0,0,1) and there is nothing
we can do to change that.

Unless Blizzard fix that my function works just as yours, I tested it
and it really does ... so I doubt that my calculations are wrong.

If you pass a roll angle value different than 0,180,360 ... then weird
stuff happens. The roll angle depends on the position of the Up vector,
that's why it doesn't work, so set the t_roll variable to 0 and the
function does change yaw+pitch properly.

I'm not gonna argue with you about your calculation being right or wrong, I didn't take my time to read through everything. I just thought you did too much for a single 3D rotation (and seeing that you increased the pitch parameter without it doing a whole circle told me something is wrong as well).
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top