Moving multiple objects
#1

Hello,
i want to move 34 object at the same time from coord Z=-11.8824 to coord Z=-14.3424

Coords X and Y stay same.

I there any option to create a "object group" and move all objects, or i need to Get possition of every 1 object and move them separated?

Thanks
Reply
#2

You can put them into an array and loop tho them
Like
PHP код:
new array[N];
array[
0] = CreateObject();
Etc 
Reply
#3

This is a translation of my post in the Portuguese section.

---

Admit that A and B are two points in the 3D space, such that:


A = [a1, a2, a3]
B = [b1, b2, b3]

k[k1, k2, k3], such that k represents the movement of the two aforementioned points in the 3D space.

C and D represent, respectively, the new coordinates of A and B after the translation defined by k is applied to the points.

Thefore, we get:

C = [a1 + k1, a2 + k2, a3 + k3]
D = [b1 + k1, b2 + k2, b3 + k3]

----

Example:

A = [3, 2, 1]
B = [5, 1, 6]

k[6, 2, 6].

C = [9, 4, 7]
D = [11, 3, 12]



To sum this up in one phrase, you just need to make sure that the difference between the coordinates is the same before and after the translation. This concept works in the 2D and 3D space.

pawn Код:
#include <a_samp>
#include <streamer>
#include <sscanf2>
#include <Pawn.CMD>

main() {}

new g_Objects[2];

public OnGameModeInit() {
    g_Objects[0] = CreateDynamicObject(2000, 165.72412, 1718.35168, 16.62031, 0.00000, 0.00000, 0.00000); // A
    g_Objects[1] = CreateDynamicObject(2000, 160.16754, 1727.65771, 16.62031, 0.00000, 0.00000, 0.00000); // B
    return 1; }
   
CMD:move(playerid, params[]) {
    // A = (3, 2)
    // B = (5, 6)
    // C = (6, 0) -> A after translation
    // D = (8, 4)
   
    new Float:newPos[3],
   
    // New position of A.
   
    Float:aObjPos[3], // Initial position of A.
   
    Float:bObjPos[3], // Initial position of B.
   
    Float:distance[3]; // Coordinates difference between B and A.
   
    if(sscanf(params, "fff", newPos[0], newPos[1], newPos[2])) return SendClientMessage(playerid, -1, "Usage: /move Float:x Float:y Float:z");
   
    GetDynamicObjectPos(g_Objects[0], aObjPos[0], aObjPos[1], aObjPos[2]); // Obtain the coordinates of A, passed by refence to aObjPos.
   
    GetDynamicObjectPos(g_Objects[1], bObjPos[0], bObjPos[1], bObjPos[2]); // Obtain the coordinates of B, passed by refence to bObjPos.
   
    // Calculating the distance between B and A's coordinates.
   
    //distance[0] = bObjPos[0] - aObjPos[0];
    //distance[1] = bObjPos[1] - aObjPos[1];
    //distance[2] = bObjPos[2] - aObjPos[2];
   
    for(new i = 0; i < sizeof distance; i++) {
        distance[i] = bObjPos[i] - aObjPos[i];
    }
   
    SetDynamicObjectPos(g_Objects[0], newPos[0], newPos[1], newPos[2]);
   
    // Apply the inputted coordinates to object A.
   
    SetDynamicObjectPos(g_Objects[1], newPos[0] + distance[0], newPos[1] + distance[1], newPos[2] + distance[2]);
   
    // To B, we apply A's coordinates + the distance between the coordinates of the initial positions.
    SetDynamicObjectPos(g_Objects[2], newPos[0] + distance[0], newPos[1] + distance[1], newPos[2] + distance[2]);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)