SA-MP Forums Archive
[Tutorial] Axis and Angles/rotation of attached Objects - 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)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] Axis and Angles/rotation of attached Objects (/showthread.php?tid=237412)



Axis and Angles/rotation of attached Objects - bhaveshnande - 09.03.2011

In this tutorial I will try to explain the X, Y and Z coordinate system that SAMP uses for its attached objects, also I will cover the coordinates and angles which you need while attaching object to a player.

Contents Player Attached Object Coordinates

I've seen many people in the scripting discussion section asking about how to set values in SetPlayerAttachedObject, so this tutorial would explain it to them. Without wasting much time lets start.

So SetPlayerAttachedObject needs offset to be set for objects to be attached at the right position, it has foffsetX, foffsetY and foffsetZ. Offset decides distance of the object from center of the bone which you select.

foffsetX : Distance of Object on X axis from center of bone
foffsetY : Distance of Object on Y axis from center of bone
foffsetZ : Distance of Object on Z axis from center of bone

Now lets understand which one is X, Y and Z axis.
I'll use a money bag example here, money bag has ID:1550
If you just attach the money bag to spine(bone) without any other tweaks it gets attached like this

SetPlayerAttachedObject(playerid, 1, 1550, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1);



Now we need to adjust its position.
If you try setting foffsetX to 1, the object moves along X axis above the player, this means X axis is the vertical line in SAMP.

SetPlayerAttachedObject(playerid, 1, 1550, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1);



Similarly you can try with Y and Z axis.
We've found that X axis is the vertical axis, Y axis is the horizontal axis going through the player from his front to the back and Z axis goes horizontal through the player from left to right.

X, Y and Z axis of a player are shown below using ****** Sketchup.



This picture clearly shows the X, Y and Z axis of a player object, also the +ve and -ve directions are shown.

Player Attached Objects Angles

Now we will learn about the angles, you need to set them for every axis to turn or to rotate the object as you want.
We have 3 values
fRotX : Rotation about X axis
fRotY : Rotation about Y axis
fRotZ : Rotation about Z axis

Lets try inserting 90° in place of fRotX
SetPlayerAttachedObject(playerid, 1, 1550, 1, 0, 0, 0, 90, 0, 0, 1, 1, 1);
That will give you something like this.



Now try changing it to 180°, it will turns the object exactly upside down.

In the picture below i've shown the degrees of rotation along X axis. The original position at which the object spawns when you keep the fRotX field blank is 0 degrees. If you change it to 90°, it will rotate backwards and so on. You can even insert negative values here. Its similar to the geometry that you all have learnt in your schools, the maximum value here is 360 degrees.



You can try yourself the same rotation changes for Y and Z axis.

Here are the rotation degrees for Y axis:



And Z axis:



Note : You need to set the fScaleX, fScaleY and fScaleZ values greater than 0, if you keep these values zero the object will become invisible.
Settings the values of fScaleX, fScaleY and fScaleZ to 1 keeps the size of object original. You can change this value to any integer you like.

Map Coordinates

Well here's a small tip about map coordinates. Apart from player attached object axis the map axis are different.
X axis on the map refers the east and west directions while Y axis denote north-south directions. Z axis is for height.

Thats all for now! It was my first tutorial so correct me if I am wrong somewhere


Re: Axis and Angles/rotation of attached Objects - sleepysnowflake - 09.03.2011

Amazing! Thank you ! :O


Re: Axis and Angles/rotation of attached Objects - Stigg - 09.03.2011

Now thats what i call a tutorial. Great work. 11/10
You can't ask for more.


Re: Axis and Angles/rotation of attached Objects - Medal Of Honor team - 09.03.2011

Very nice one!!!


Re: Axis and Angles/rotation of attached Objects - CyNiC - 09.03.2011

Very useful, it can help many people that don't understand about theses positions.


Re: Axis and Angles/rotation of attached Objects - XFlawless - 10.03.2011

Very useful for setting Camera positions...etc.


Re: Axis and Angles/rotation of attached Objects - bhaveshnande - 10.03.2011

Thank u all for sweet comments :P


Re: Axis and Angles/rotation of attached Objects - black_dota - 10.03.2011

I like your ****** Sketchup

Nice tutorial!

pawn Code:
This forum requires that you wait 60 seconds between posts. Please try again in 15 seconds.
Ah...


Re: Axis and Angles/rotation of attached Objects - bhaveshnande - 10.03.2011

Quote:

I like your ****** Sketchup
Nice tutorial!

Ty Well ****** Sketchup was the only way for me to show all the rotation angles And in addition, its Free!


Re: Axis and Angles/rotation of attached Objects - [SFA]SpiRRiT - 13.03.2011

Awesomee!!


Re: Axis and Angles/rotation of attached Objects - [SFA]SpiRRiT - 13.03.2011

Keep up the good work


Re: Axis and Angles/rotation of attached Objects - boelie - 13.03.2011

im using someones FS to place an object on a player but your tutorial sure made me understand it more
great examples i like the pictures


Re: Axis and Angles/rotation of attached Objects - royal_king - 17.08.2011

This is what called as tutorial! it's really amazing! it's like how teachers explain on boards xD!


Re: Axis and Angles/rotation of attached Objects - Hiddos - 17.08.2011

Quote:
Originally Posted by bhaveshnande
View Post
You messed up the Z and X axis ^^.


Re: Axis and Angles/rotation of attached Objects - Lofti - 30.08.2015

Very helpful topic, it is helping me alot !


Re: Axis and Angles/rotation of attached Objects - Emmet_ - 30.08.2015

Quote:
Originally Posted by Lofti
View Post
Very helpful topic, it is helping me alot !
nice 4 year bump


Re: Axis and Angles/rotation of attached Objects - Eoussama - 08.10.2016

Would this work on non-attached objects?