PDA

View Full Version : GetDynamicObjectPos & OnPlayerShootDynamicObject reading wrong coordinates


Fmfan
02/04/2019, 01:12 PM
Hi everyone,

I have problem with GetDynamicObjectPos and OnPlayerShootDynamicObject which are not getting coordinates right. I spent few hours trying to find solution but without any luck so I was hopping you guys can help me. You can see at the picture below that script is clearly getting coordinates and distance between player and object wrong.

This is object I created.

CreateDynamicObject(19315, 1227.5359, -4454.4858, 23.4837, 0.00000, 0.00000, 0.00000, -1, -1, -1, 300.00, 300.00);


This is a code from script.

public OnPlayerShootDynamicObject(playerid, weaponid, objectid, Float:x, Float:y, Float:z)
{
new
Float: fDistance = GetPlayerDistanceFromPoint(playerid, x, y, z),
sString[256],
sString2[256];

format(sString, sizeof(sString), "Weapon %i. Object: %i. Pos of Object: %f, %f, %f", weaponid, objectid, x, y, z);
format(sString2, sizeof(sString2), "Distance between you and Object is %0.2f.", fDistance);
SendClientMessage(playerid, -1, sString);
SendClientMessage(playerid, 0xA9C4E4FF, sString2);
return 1;
}


Any help would be appreciated.

NaS
02/04/2019, 01:35 PM
Those seem to be the offsets of the shot hit position to the object's center position.

You could use GetDynamicObjectPos to obtain the object's position. Then add the offset to the center position and you have the correct hit coords.

Fmfan
02/04/2019, 01:46 PM
Those seem to be the offsets of the shot hit position to the object's center position.

You could use GetDynamicObjectPos to obtain the object's position. Then add the offset to the center position and you have the correct hit coords.

I just realized I inserted wrong function in thread title and explained another thing in post :rolleyes:. Thank you, you're answer helped ;)

RedFusion
02/04/2019, 04:34 PM
Here's a suggestion for you that might help accomplishing what you want: https://forum.sa-mp.com/showpost.php?p=1487836&postcount=2639