Problem position AttachDynamicObjectToVehicle
#1

I made the following code:

pawn Код:
VehiculosInfo[vehicleid][cObjetoToy][0] = modelid;
VehiculosInfo[vehicleid][cObjetoToy][0] = CreateDynamicObject(VehiculosInfo[vehicleid][cToy][0], x,y,z,0.0,0.0,0.0, 0, 0);
ObjetoGuardar[playerid] = 11;
IDObjetoGuardar[playerid] = 0;
EditDynamicObject(playerid, VehiculosInfo[vehicleid][cObjetoToy][0]);

It creates the object correctly and lets me edit it but the problem is when saving the object to the new position that does not correctly save the coordinates.

This is the save code in function OnPlayerEditDynamicObject.

pawn Код:
new vehicleid = GetPlayerVehicleID(playerid);
VehiculosInfo[vehicleid][cPosToy][0] = x;
VehiculosInfo[vehicleid][cPosToy][1] = y;
VehiculosInfo[vehicleid][cPosToy][2] = z;
VehiculosInfo[vehicleid][cPosToy][3] = rx;
VehiculosInfo[vehicleid][cPosToy][4] = ry;
VehiculosInfo[vehicleid][cPosToy][5] = rz;
SetDynamicObjectPos(objectid, x, y, z);
SetDynamicObjectRot(objectid, rx, ry, rz);
DestroyDynamicObject(VehiculosInfo[vehicleid][cObjetoToy][IDObjetoGuardar[playerid]]);
VehiculosInfo[vehicleid][cObjetoToy][IDObjetoGuardar[playerid]] = CreateDynamicObject(VehiculosInfo[vehicleid][cToy][IDObjetoGuardar[playerid]], VehiculosInfo[vehicleid][cPosToy][0], VehiculosInfo[vehicleid][cPosToy][1], VehiculosInfo[vehicleid][cPosToy][2], VehiculosInfo[vehicleid][cPosToy][3], VehiculosInfo[vehicleid][cPosToy][4], VehiculosInfo[vehicleid][cPosToy][5], 0, 0);
AttachDynamicObjectToVehicle(VehiculosInfo[vehicleid][cObjetoToy][IDObjetoGuardar[playerid]], vehicleid, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0);
+rep To whom I solve it.
Reply
#2

new Floatfx, Floatfy, Floatfz, Floatfaz,
Float:finalx, Float:finaly,
Floatx, Floaty, Floatz, Float:roz;
GetVehiclePos(vehicle, px, py, pz);
GetVehicleZAngle(vehicle, roz);
ofx = x-px;
ofy = y-py;
ofz = z-pz;
ofaz = rz-roz;
finalx = ofx*floatcos(roz, degrees)+ofy*floatsin(roz, degrees);
finaly = -ofx*floatsin(roz, degrees)+ofy*floatcos(roz, degrees);



use CreatePlayerObject or CreateObject when you click finish then execute these codes and attachobjecttovehicle
Reply
#3

Quote:
Originally Posted by SetPlayerNameTag
Посмотреть сообщение
new Floatfx, Floatfy, Floatfz, Floatfaz,
Float:finalx, Float:finaly,
Floatx, Floaty, Floatz, Float:roz;
GetVehiclePos(vehicle, px, py, pz);
GetVehicleZAngle(vehicle, roz);
ofx = x-px;
ofy = y-py;
ofz = z-pz;
ofaz = rz-roz;
finalx = ofx*floatcos(roz, degrees)+ofy*floatsin(roz, degrees);
finaly = -ofx*floatsin(roz, degrees)+ofy*floatcos(roz, degrees);



use CreatePlayerObject or CreateObject when you click finish then execute these codes and attachobjecttovehicle
Still not working because it puts the object in a wrong position.

Code:
pawn Код:
new Float:ofx, Float:ofy, Float:ofz, Float:ofaz,Float:finalx, Float:finaly, Float:px, Float:py, Float:pz, Float:roz;
GetVehiclePos(vehicleid, px, py, pz);
GetVehicleZAngle(vehicleid, roz);
ofx = x-px;
ofy = y-py;
ofz = z-pz;
ofaz = rz-roz;
finalx = ofx*floatcos(roz, degrees)+ofy*floatsin(roz, degrees);
finaly = -ofx*floatsin(roz, degrees)+ofy*floatcos(roz, degrees);
AttachDynamicObjectToVehicle(VehiculosInfo[vehicleid][cObjetoToy][IDObjetoGuardar[playerid]], vehicleid, ofx, ofy, ofz, ofaz, finalx, finaly);
їWhich is the error?.
Reply
#4

This is never going to work right you need to do a number of things to do this correctly.

https://github.com/Pottus/Texture-St...o/vehicles.pwn
Код:
	else if(response == EDIT_RESPONSE_UPDATE)
	{
		new Float:tmpx, Float:tmpy, Float:tmpz;

		new refindex = GetCarObjectRefIndex(ObjectData[CurrObject[playerid]][oAttachedVehicle], CurrObject[playerid]);

	    tmpx = x - AVEditPos[playerid][0];
	    tmpy = y - AVEditPos[playerid][1];
	    tmpz = z - AVEditPos[playerid][2];

        CarData[ObjectData[CurrObject[playerid]][oAttachedVehicle]][COX][refindex] = tmpx;
	    CarData[ObjectData[CurrObject[playerid]][oAttachedVehicle]][COY][refindex] = tmpy;
        CarData[ObjectData[CurrObject[playerid]][oAttachedVehicle]][COZ][refindex] = tmpz;
        
        CarData[ObjectData[CurrObject[playerid]][oAttachedVehicle]][CORX][refindex] = rx;
	    CarData[ObjectData[CurrObject[playerid]][oAttachedVehicle]][CORY][refindex] = ry;
        CarData[ObjectData[CurrObject[playerid]][oAttachedVehicle]][CORZ][refindex] = rz;
        
        SetVehicleZAngle(CarData[ObjectData[CurrObject[playerid]][oAttachedVehicle]][CarID], 0.0);

        UpdateAttachedVehicleObject(ObjectData[CurrObject[playerid]][oAttachedVehicle], refindex, VEHICLE_ATTACH_UPDATE);
	
	}
Код:
UpdateAttachedVehicleObject(carindex, refindex, type)
{
	if(type == VEHICLE_ATTACH_UPDATE)
	{
	    Streamer_SetFloatData(STREAMER_TYPE_OBJECT, ObjectData[CarData[carindex][CarObjectRef][refindex]][oID], E_STREAMER_ATTACH_OFFSET_X, CarData[carindex][COX][refindex]);
	    Streamer_SetFloatData(STREAMER_TYPE_OBJECT, ObjectData[CarData[carindex][CarObjectRef][refindex]][oID], E_STREAMER_ATTACH_OFFSET_Y, CarData[carindex][COY][refindex]);
	    Streamer_SetFloatData(STREAMER_TYPE_OBJECT, ObjectData[CarData[carindex][CarObjectRef][refindex]][oID], E_STREAMER_ATTACH_OFFSET_Z, CarData[carindex][COZ][refindex]);
	    Streamer_SetFloatData(STREAMER_TYPE_OBJECT, ObjectData[CarData[carindex][CarObjectRef][refindex]][oID], E_STREAMER_ATTACH_R_X, CarData[carindex][CORX][refindex]);
	    Streamer_SetFloatData(STREAMER_TYPE_OBJECT, ObjectData[CarData[carindex][CarObjectRef][refindex]][oID], E_STREAMER_ATTACH_R_Y, CarData[carindex][CORY][refindex]);
	    Streamer_SetFloatData(STREAMER_TYPE_OBJECT, ObjectData[CarData[carindex][CarObjectRef][refindex]][oID], E_STREAMER_ATTACH_R_Z, CarData[carindex][CORZ][refindex]);

	}
	else if(type == VEHICLE_REATTACH_UPDATE)
	{
		refindex = GetCarObjectRefIndex(carindex, refindex);
		
	    AttachDynamicObjectToVehicle(ObjectData[CarData[carindex][CarObjectRef][refindex]][oID], CarData[carindex][CarID],
			CarData[carindex][COX][refindex], CarData[carindex][COY][refindex], CarData[carindex][COZ][refindex],
			CarData[carindex][CORX][refindex], CarData[carindex][CORY][refindex], CarData[carindex][CORZ][refindex]
		);
	}

	UpdateObject3DText(CarData[carindex][CarObjectRef][refindex], false);

	return 1;
}
Reply
#5

Quote:
Originally Posted by Pottus
Посмотреть сообщение
This is never going to work right you need to do a number of things to do this correctly.
їFor example?.
Reply
#6

1.) Create dummy object golf ball 1974
2.) Edit that object
3.) Save origin
4.) Subject the origin from the current position

Код:
  tmpx = x - AVEditPos[playerid][0];
	    tmpy = y - AVEditPos[playerid][1];
	    tmpz = z - AVEditPos[playerid][2];
5.) Update attached object position on vehicle
6.) Set vehicle z-angle to 0.0 (always use this angle to save yourself a lot of trouble)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)