yagr_MoveGroup(groupid, Float:X, Float:Y, Float:Z, Float:rZ, Float:Speed)
{
if(!Iter_Contains(ValidGroups, groupid))
return 0;
new Float:CoordCenter[3], Float:ObjectPos[6], nmax, Float:g_sin[3], Float:g_cos[3];
yagr_GetCenterCoords(groupid, CoordCenter[0], CoordCenter[1], CoordCenter[2]);
for(new i; i < MAX_GROUP_OBJECTS; i ++)
{
if(GroupInfo[groupid][yagr_objectid][i] != -1)
{
yagr_GetObjectPos(groupid, GroupInfo[groupid][yagr_objectid][i], ObjectPos[0], ObjectPos[1], ObjectPos[2], ObjectPos[3], ObjectPos[4], ObjectPos[5]);
GroupInfo[groupid][yagr_obdestinyX][i] = X + (ObjectPos[0]-CoordCenter[0]);
GroupInfo[groupid][yagr_obdestinyY][i] = Y + (ObjectPos[1]-CoordCenter[1]);
GroupInfo[groupid][yagr_obdestinyZ][i] = Z + (ObjectPos[2]-CoordCenter[2]);
yagr_ConverterValores(ObjectPos[3], ObjectPos[4], ObjectPos[5]-rZ, g_sin, g_cos);
GroupInfo[groupid][yagr_obdestinyRZ][i] = atan2(g_cos[0] * g_sin[2] - g_cos[2] * g_sin[0] * g_sin[1], g_cos[0] * g_cos[2] + g_sin[0] * g_sin[1] * g_sin[2]);
nmax = i;
}
}
for(new i; i < nmax; i ++)
{
if(GroupInfo[groupid][yagr_objectid][i] != -1)
{
if(GroupInfo[groupid][yagr_objectdynamic][i])
MoveDynamicObject(GroupInfo[groupid][yagr_objectid][i], GroupInfo[groupid][yagr_obdestinyX][i], GroupInfo[groupid][yagr_obdestinyY][i], GroupInfo[groupid][yagr_obdestinyZ][i], Speed, GroupInfo[groupid][yagr_originRX][i], GroupInfo[groupid][yagr_originRY][i], GroupInfo[groupid][yagr_obdestinyRZ][i]);
else
MoveObject(GroupInfo[groupid][yagr_objectid][i], GroupInfo[groupid][yagr_obdestinyX][i], GroupInfo[groupid][yagr_obdestinyY][i], GroupInfo[groupid][yagr_obdestinyZ][i], Speed, GroupInfo[groupid][yagr_originRX][i], GroupInfo[groupid][yagr_originRY][i], GroupInfo[groupid][yagr_obdestinyRZ][i]);
}
}
return 1;
}
yagr_GetCenterCoords(groupid, &Float:X, &Float:Y, &Float:Z)
{
new Float:highX = -9999999.0;
new Float:highY = -9999999.0;
new Float:highZ = -9999999.0;
new Float:lowX = 9999999.0;
new Float:lowY = 9999999.0;
new Float:lowZ = 9999999.0;
new count, Float:oX, Float:oY, Float:oZ, Float:null;
for(new i; i < MAX_GROUP_OBJECTS; i ++)
{
if(GroupInfo[groupid][yagr_objectid][i] != -1)
{
yagr_GetObjectPos(groupid, GroupInfo[groupid][yagr_objectid][i], oX, oY, oZ, null, null, null);
if(oX > highX) highX = oX;
if(oY > highY) highY = oY;
if(oZ > highZ) highZ = oZ;
if(oX < lowX) lowX = oX;
if(oY < lowY) lowY = oY;
if(oZ < lowZ) lowZ = oZ;
count++;
}
}
if(count < 1) return 0;
X = (highX + lowX) / 2;
Y = (highY + lowY) / 2;
Z = (highZ + lowZ) / 2;
return 1;
}
yagr_ConverterValores(Float:rot_x, Float:rot_y, Float:rot_z, Float:sin[3], Float:cos[3])
{
sin[0] = floatsin(rot_x, degrees);
sin[1] = floatsin(rot_y, degrees);
sin[2] = floatsin(rot_z, degrees);
cos[0] = floatcos(rot_x, degrees);
cos[1] = floatcos(rot_y, degrees);
cos[2] = floatcos(rot_z, degrees);
return 1;
}
|
It's not possible to include rotation when you only try to make it with one movement, as the objects need to rotate around a pivot to stay "in sync" with each other.
You can use YSF to attach all objects to a pivot object, move + rotate the pivot object and after that deattach them again (you can calculate the final positions including rotations). Except you don't want them to stay together while moving, then you'd only need to calculate the final positions using a pivot and move all objects there in a straight line. |
yagr_GetCenterCoords(groupid, CoordCenter[0], CoordCenter[1], CoordCenter[2]);
