SA-MP Forums Archive
Setting an object rotation by the player's camera vector? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Setting an object rotation by the player's camera vector? (/showthread.php?tid=174051)



Setting an object rotation by the player's camera vector? - [XST]O_x - 04.09.2010

Well,yes,is it possible?

Since I've tried making it and it was just fucked up.
Maybe I miscalculated something.

This is how I tried to make it however:
pawn Code:
SetObjectRot(missile_object[i],VehCameraPos[i][0]+VehVectorPos[i][0],VehCameraPos[i][1]+VehVectorPos[i][1],VehCameraPos[i][2]+VehVectorPos[i][2]);
There are no problems with the camera vector storing since the explosions are creating correctly:
pawn Code:
CreateExplosion(VehCameraPos[i2][0]+(VehVectorPos[i2][0] * Dist)+OffSet[i2][0],VehCameraPos[i2][1]+(VehVectorPos[i2][1] * Dist)+OffSet[i2][1],VehCameraPos[i2][2]+(VehVectorPos[i2][2] * Dist)+OffSet[i2][2],7,100);
So the problem is in SetObjectRot, is there any way of solving this issue? Or at least any alternatives would be highly appreciated.

And sorry, this is the first time I'm messing with camera vectors.


Re: Setting an object rotation by the player's camera vector? - Mauzen - 04.09.2010

Yeah, this is quite annoying, because object rotation and stuff like atan do not always use the same scales.
It should work like this, took me a while to get the right offsets, but i needed it for a fs:

SetObjectRot(object, asin(z_vector), 0.0, 360 - atan2(x_vector, y_vetor));


Re: Setting an object rotation by the player's camera vector? - [XST]O_x - 04.09.2010

Thanks a lot! Works just fine.



AW: Setting an object rotation by the player's camera vector? - Trooper[Y] - 14.07.2012

As i have that problem too,
i tested that code but it doesnt change the rotation of the (attached) object:

new Float:tfx[6];
GetPlayerCameraFrontVector(playerid, tfx[0],tfx[1],tfx[2]);
SetObjectRot(gunobj, asin(tfx[2]), 0.0, 360 - atan2( tfx[0], tfx[1]));