////////////////////////////////////////////////////
// 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));
}