• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

How Do you Change a Units Pitch After Unit Is Made With code?

Status
Not open for further replies.
Level 12
Joined
Feb 23, 2008
Messages
587
What?
I would like function that will change the units pitch. (A Unit Made After The Map Has Started)

Why
Will Make Roller Coaster Map alot easier to make and maintain.

Note: I am not looking how to change a doodads pitch in the editor.
This is something that can be run in the game.

Desired Function
-----------------------------
- ChangeUnitAngles(Unit, Yaw, Pitch)
-
- The function takes the a unit and the desired pitch and yaw.
- It then changes the pitch and yaw of the unit.
-----------------------------

This Is what I mean When i say "Pitch" And "Yaw":

325px-Flight_dynamics_with_text.png


Any Ideas?
 
Last edited:
Level 12
Joined
Feb 23, 2008
Messages
587
Hmm.. K This is what I have so far. Basically. It will tilt it only so much.

What your saying sounds like I can tell it to change to any degree over time of some sort. so Ill look into that.

I have a function that does what I want. But it max's out at about 70 degrees.
check it out.

(Map Below, Attempts to change the Yaw and Pitch on a loop every .1 or .01 sec. It Cycles though 1-360)
 

Attachments

  • Create Unit And Change Pitch.SC2Map
    15.1 KB · Views: 83

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
I guess you could always use a custom model if there is no solution.

Where are the functions used in "libNtve_gf_SendActorMessageToUnit(lp_actor, libNtve_gf_SetRotation(lv_forwardX, lv_forwardY, lv_forwardZ, lv_upX, lv_upY, lv_upZ));"
I do not see them difined neithor are they parts of the standard natives. Or are they GUI functions.

I am amazed you are doing it without a custom actor event data.
 
Level 12
Joined
Feb 23, 2008
Messages
587
Whats Required For Roller Coaster

In theory All I need is 180 degrees turn Because If its upside up and its a track you cant tell anyway because both sides are the same.

The Issue is For some reason in warcraft 3 the bottom of the track was shaded and looked funny on loops if part of the loop was shaded on the inside and part wasn't because I rotated the yaw to make it look like its upside down.

With Starcraft 2 It might not auto shade the bottom or It could have been the person who made the model sprayed the bottom of the track with shade.
But Assuming this isn't the case, and I can remove the shade form the model if it had one or if starcraft 2 doesn't auto do that I should be ok.


The New Map
I was able to achieve 90 degree turn and 180 degrees turning total.
I Also Changed the model to a Cube So I could tell how much it was turning better.

O I am using moonlight so it might hide the code
Here is my full script.

Code:
////////////////////////////////////////////////////
// Trigger Variables
////////////////////////////////////////////////////
trigger AfterInit;
trigger Spin;

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

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

////////////////////////////////////////////////////
// At Init                                        //
////////////////////////////////////////////////////
void AtInit()
{ 
    
    //Introduction
    TriggerDebugOutput(1, StringToText("Create a Unit And Then Change Pitch With MoonLight"), true);
    TriggerDebugOutput(1, StringToText("Version 1.0"), true);
    TriggerDebugOutput(1, StringToText(" "), true);
    
    //Create Unit
    TriggerDebugOutput(1, StringToText("Create Unit"), true);
    TriggerDebugOutput(1, StringToText(" "), true);
    libNtve_gf_CreateUnitsAtPoint2(1, "ShapeBox", 0, 1, RegionGetCenter(RegionPlayableMap()));
//    libNtve_gf_CreateUnitsAtPoint2(1, "SCV", 0, 1, RegionGetCenter(RegionPlayableMap()));
    UnitSetHeight(UnitLastCreated(), 3, 0.0);

    aUnit = UnitLastCreated();        
    
    //Set Up Timer
    TriggerDebugOutput(1, StringToText("Setup timer To change pitch"), true);
    TriggerDebugOutput(1, StringToText(" "), true);
    AfterInit_Init();
    
    //Set Up Spiner
    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;

    if (pitchG > 360)
    {
        pitchG = -360;
    }
    
    ChangePitch(aUnit,pitchG);
    return true;
}

//--------------------------------------------------------------------------------------------------
void Spin_Init ()
{
    Spin = TriggerCreate("Spin_Func");
    TriggerAddEventTimePeriodic(Spin, .001, c_timeGame);
}
////////////////////////////////////////////////////
// Game Fuctions                                  //
////////////////////////////////////////////////////
void ChangePitch(unit myUnit, fixed mypitch)
{
    TriggerDebugOutput(1, StringToText("Change Pitch Of Unit To " + mypitch + "."), true);
    TriggerDebugOutput(1, StringToText(" "), true);    
    ChangeOrientation(myUnit, UnitGetFacing(myUnit), mypitch);  
}

void ChangeOrientation (unit lp_actor, fixed lp_yaw, fixed pitch) 
{    
    TriggerDebugOutput(1, StringToText("Change Orientation Of Unit."), true);
    //TriggerDebugOutput(1, StringToText("Yaw = " + lp_yaw + " Pitch = " + lp_pitch), true);    
    TriggerDebugOutput(1, StringToText("Pitch = " + pitch), true);
    TriggerDebugOutput(1, StringToText(" "), true);    
    
    //Pre-Set Orientation
    fixed lp_roll = 0;
    
    // Variable Declarations
    fixed lv_forwardX;
    fixed lv_forwardY;
    fixed lv_forwardZ;
    fixed lv_upX;
    fixed lv_upY;
    fixed lv_upZ;

    // Variable Initialization
//    lv_forwardX =  0;
//    lv_forwardY =  0;
//    lv_forwardZ =  0;
//    lv_upX =  0;
//    lv_upY =  0;
//    lv_upZ = 0;
    
    lv_forwardX = Cos(lp_yaw);
    lv_forwardY = Sin(lp_yaw);
    lv_forwardZ = Sin(lp_pitch);
    lv_upX = Cos(lp_roll);
    lv_upY = Sin(lp_roll);
    lv_upZ = Cos(lp_pitch);
    
//    lv_forwardX = -Sin(pitch);
//    lv_forwardY = Cos(pitch)/(Cos(pitch)*Cos(pitch)+Sin(pitch)*Sin(pitch));
//    lv_forwardZ = Sin(pitch)/(Cos(pitch)*Cos(pitch)+Sin(pitch)*Sin(pitch));
//    lv_upX = Cos(lp_roll);
//    lv_upY = Sin(lp_roll);
//    lv_upZ = Cos(pitch);
    // Implementation
    libNtve_gf_SendActorMessageToUnit(lp_actor, libNtve_gf_SetRotation(lv_forwardX, lv_forwardY, lv_forwardZ, lv_upX, lv_upY, lv_upZ));
}
 

Attachments

  • Create Unit And Change Pitch.SC2Map
    15.1 KB · Views: 80
Level 12
Joined
Feb 23, 2008
Messages
587
Solved

Does Pitch 360!

this only does pitch, Now having issues working in the yaw also.

Arkless told me how to change it to work. Here is hes test map. And it works great.
Note - Fly Units only. The map I have above would have worked if i tested it with a flying unit.

Its pretty much the same but heres the full code (Non Moonlight) Just straight code.

Code:
include "TriggerLibs/NativeLib"
unit UTest;
fixed ATest = 0.0;
void SetPitch(unit Target, fixed pitch)
{
    fixed Out_X;
    fixed Out_Y;
    fixed Out_Z;
    fixed Up_X;
    fixed Up_Y;
    fixed Up_Z;
    Out_Y = 0;
    Out_X = Cos(pitch)/(Cos(pitch)*Cos(pitch)+Sin(pitch)*Sin(pitch));
    Out_Z = Sin(pitch)/(Cos(pitch)*Cos(pitch)+Sin(pitch)*Sin(pitch));
    Up_Y = 0;
    Up_X = 0;// (-Sin(pitch))/((-Sin(pitch))*(-Sin(pitch))+Cos(pitch)*Cos(pitch));
    Up_Z = 0;// Cos(pitch)/((-Sin(pitch))*(-Sin(pitch))+Cos(pitch)*Cos(pitch));
    
    libNtve_gf_SendActorMessageToUnit(UTest, libNtve_gf_SetRotation(Out_X, Out_Y, Out_Z, Up_X, Up_Y, Up_Z));
}
bool PTest (bool a, bool b){
    ATest = ATest + 2.0;
    
    SetPitch(UTest,ATest);
    
    return true;
}
void teststuff () {
    trigger t;
    UnitCreate(1,"VoidRay",c_unitCreateIgnorePlacement,1,RegionGetCenter(RegionEntireMap()),0);
    UTest = UnitLastCreated();
    t = TriggerCreate("PTest");
    TriggerAddEventTimePeriodic(t,0.01,c_timeGame);
}
 

Attachments

  • poke.SC2Map
    21 KB · Views: 72
Last edited:
Status
Not open for further replies.
Top