AttachObjectToObject messing up objects
#1

I'm trying to attach objects to the first object, but it seems to be messing it up.
So, when creating the objects, everything looks fine, but when attaching objects 2-6 to object 1, it won't work and I calculate the offsets accordingly, at least I think.

That's the code I create the objects with:
pawn Код:
for(new i=0; i<sizeof(NukeObject); i++)
{
    if(NukeObject[i][ObjID] == 0 || !IsValidObject(NukeObject[i][ObjID]))
    NukeObject[i][ObjID] = CreateObject(NukeObject[i][ModelID], NukeObject[i][PosX], NukeObject[i][PosY], NukeObject[i][PosZ], NukeObject[i][PosRX], NukeObject[i][PosRY], NukeObject[i][PosRZ]);
}
And that's the code I attach the objects in a different command:
pawn Код:
for(new i=1; i<sizeof(NukeObject); i++)
{
    if(i > 0)
    {
        new Float:tposx = NukeObject[i][PosX]-NukeObject[0][PosX], Float:tposy = NukeObject[i][PosY]-NukeObject[0][PosY], Float:tposz = NukeObject[i][PosZ]-NukeObject[0][PosZ];
    new Float:tposrx = NukeObject[i][PosRX]-NukeObject[0][PosRX], Float:tposry = NukeObject[i][PosRY]-NukeObject[0][PosRY], Float:tposrz = NukeObject[i][PosRZ]-NukeObject[0][PosRZ];
        AttachObjectToObject(NukeObject[i][ObjID], NukeObject[0][ObjID], tposx, tposy, tposz, tposrx, tposry, tposrz, 1);
    }
}
Reply
#2

What're you trying to do? Are you trying to attach all the NukeObject's to NukeObject 0?

What messes it up and how doesn't it work?

FYI, there's no reason to do if(i > 0) if your loop is set to start at 1.
Reply
#3

Quote:
Originally Posted by Arthur Kane
Посмотреть сообщение
What're you trying to do? Are you trying to attach all the NukeObject's to NukeObject 0?

What messes it up and how doesn't it work?

FYI, there's no reason to do if(i > 0) if your loop is set to start at 1.
Ye I know, I took it out from the CreateObject loop, so I had this condition.

Anyway, I'm calculating the offsets, but the attached object's location is not the same as it was when created (as should). I'm thinking it might be caused by a rotation issue other than regular XYZ.
That's an example of how it looks like after attaching with the code above: http://i.imgur.com/xVZl57o.png
And this is how it should look like: http://i.imgur.com/IqRaELj.png
Reply
#4

Okay I found out AttachObjectToObject offsets are really messy in the code itself, I don't know what's causing it really.

If someone is interested about how I fixed it:

pawn Код:
new Float:tposx = NukeObject[i][PosX]-NukeObject[0][PosX], Float:tposy = NukeObject[0][PosY]-NukeObject[i][PosY], Float:tposz = NukeObject[0][PosZ]-NukeObject[i][PosZ];
new Float:tposrx = NukeObject[i][PosRX]-NukeObject[0][PosRX], Float:tposry = NukeObject[i][PosRY]-NukeObject[0][PosRY], Float:tposrz = NukeObject[0][PosRZ]-NukeObject[i][PosRZ];
AttachObjectToObject(NukeObject[i][ObjID], NukeObject[0][ObjID], tposy, tposz, tposx, tposry, -tposrz, tposrx, 1);
So, generally everything is meant to be calculated by attachedobj - mainobj XYZs. But, it seems to not work that way, so I debugged it ingame quite some time, and found out that Y, Z and RZ offsets should be calculated the other way around, by mainobj - attachedobj.

Also, when attaching the object, the parameters are not (x, y, z, rx, ry, rz), they are actually (y, z, x, y, z, x).

Enjoy
Reply
#5

Quote:
Originally Posted by arad55
Посмотреть сообщение
Also, when attaching the object, the parameters are not (x, y, z, rx, ry, rz), they are actually (y, z, x, y, z, x)
That is because you are attaching objects to a rotated object! So that is not really how it is at all. The easiest solution is to use a dummy object to attach all objects to. My favourite one is the golf ball.

http://dev.prineside.com/en/gtasa_sa...4-kb_golfball/

What to do.

1.) Choose a central location (the center of all objects).
https://github.com/Pottus/Texture-St...dio/groups.pwn
line 446 - tsfunc GetGroupCenter(playerid, &Float:X, &Float:Y, &Float:Z)

Код:
	X = (highX + lowX) / 2;
	Y = (highY + lowY) / 2;
	Z = (highZ + lowZ) / 2;
Just add the highest x,y,z to the lowest x,y,z of the given set of objects and divide by 2 gives you the group center.

2.) Create golf at this position
3.) Calculate offsets
4.) Attach objects to golf ball

Make sure the ball has a rotation of 0,0,0 then the rotation of the objects you are attaching need no extra calculations let the client do the dirty work at this point.
Reply
#6

Quote:
Originally Posted by Pottus
Посмотреть сообщение
That is because you are attaching objects to a rotated object! So that is not really how it is at all.
I tried attaching to a non-rotated object as well, but it didn't work too.
Reply
#7

I didn't finish explaining
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)