The following code moves an object around in a square.
However, if I move the exact code in the loop to a makeSquare function and just call the function each iteration, the object just rotates about the z-axis and does not move forward.
Any ideas why? Working and non-working code snippets are below.
Thanks!
This works:
if( command == "square"

{
integer i;
for( i = 0; i < 4; i++)
{
radians = g_angle * PI / 180;
y_Dist = llSin(radians) * distance;
x_Dist = llCos(radians) * distance;
llSetPos( llGetPos() + < x_Dist, y_Dist, 0 > );
g_angle = g_angle + 90;
rAngle = llEuler2Rot( < 0, 0, 90 * DEG_TO_RAD * 1 >
;newRotation = llGetRot() * rAngle;
llSetRot( newRotation );
}
}
This doesn't work:
makeSquare()
{
radians = g_angle * PI / 180;
y_Dist = llSin(radians) * distance;
x_Dist = llCos(radians) * distance;
llSetPos( llGetPos() + < x_Dist, y_Dist, 0 > );
g_angle = g_angle + 90;
rAngle = llEuler2Rot( < 0, 0, 90 * DEG_TO_RAD * 1 >
;newRotation = llGetRot() * rAngle;
llSetRot( newRotation );
}
if( command == "square"

{
integer i;
for( i = 0; i < 4; i++)
{
makeSquare();
}
}