SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 09/03/2011, 05:17 PM   #1
bhaveshnande
Big Clucker
 
bhaveshnande's Avatar
 
Join Date: Dec 2010
Location: India
Posts: 111
Reputation: 21
Default Axis and Angles/rotation of attached Objects

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
  • Player attached object angles
  • Map coordinates

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
__________________
First they ignore you,
Then they laugh at you,
Then they fight you,
Then you win.

- Mohandas Karamchand Gandhi.

[Tutorial] Axis and Angles/rotations of Attached Objects
[Tool/Web/Other] BSN Textdraw Editor Online
[Tool/Web/Other] BSN Image2Textdraw Converter Online

Last edited by bhaveshnande; 10/03/2011 at 06:27 AM.
bhaveshnande is offline   Reply With Quote
Old 09/03/2011, 05:19 PM   #2
sleepysnowflake
Gangsta
 
sleepysnowflake's Avatar
 
Join Date: Dec 2009
Posts: 983
Reputation: 138
Default Re: Axis and Angles/rotation of attached Objects

Amazing! Thank you ! :O
sleepysnowflake is offline   Reply With Quote
Old 09/03/2011, 05:19 PM   #3
Stigg
High-roller
 
Stigg's Avatar
 
Join Date: Aug 2010
Location: Other side of the Universe.
Posts: 2,053
Reputation: 125
Default Re: Axis and Angles/rotation of attached Objects

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

Peace...

Stigg is offline   Reply With Quote
Old 09/03/2011, 05:19 PM   #4
Medal Of Honor team
Gangsta
 
Medal Of Honor team's Avatar
 
Join Date: Feb 2011
Location: Osama Bin Laden's house ;)
Posts: 538
Reputation: 2
Default Re: Axis and Angles/rotation of attached Objects

Very nice one!!!
__________________
Making a Social Website from scratch. Need a PHP partner
Medal Of Honor team is offline   Reply With Quote
Old 09/03/2011, 05:37 PM   #5
CyNiC
High-roller
 
Join Date: Jan 2009
Location: Brazil
Posts: 1,445
Reputation: 203
Default Re: Axis and Angles/rotation of attached Objects

Very useful, it can help many people that don't understand about theses positions.
__________________
My scripts
Brazucas'Server
CyNiC is offline   Reply With Quote
Old 10/03/2011, 05:39 AM   #6
XFlawless
Guest
 
Posts: n/a
Default Re: Axis and Angles/rotation of attached Objects

Very useful for setting Camera positions...etc.
  Reply With Quote
Old 10/03/2011, 05:48 AM   #7
bhaveshnande
Big Clucker
 
bhaveshnande's Avatar
 
Join Date: Dec 2010
Location: India
Posts: 111
Reputation: 21
Default Re: Axis and Angles/rotation of attached Objects

Thank u all for sweet comments :P
__________________
First they ignore you,
Then they laugh at you,
Then they fight you,
Then you win.

- Mohandas Karamchand Gandhi.

[Tutorial] Axis and Angles/rotations of Attached Objects
[Tool/Web/Other] BSN Textdraw Editor Online
[Tool/Web/Other] BSN Image2Textdraw Converter Online
bhaveshnande is offline   Reply With Quote
Old 10/03/2011, 06:19 AM   #8
black_dota
Big Clucker
 
Join Date: Jul 2010
Posts: 143
Reputation: 1
Default Re: Axis and Angles/rotation of attached Objects

I like your ****** Sketchup

Nice tutorial!

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

Ah...
__________________
Code:
public OnPlayerConnect(playerid)
{
    Spam(playerid, 9000, "It's Over 9000 !!!");
    return true;
}

stock Spam(playerid, number_of_times, message[])
{
    for(new c; c < number_of_times; c++) {
        SendClientMessage(playerid, 0x0099CCFF, message);
    }
    return true;
}
black_dota is offline   Reply With Quote
Old 10/03/2011, 06:23 AM   #9
bhaveshnande
Big Clucker
 
bhaveshnande's Avatar
 
Join Date: Dec 2010
Location: India
Posts: 111
Reputation: 21
Default Re: Axis and Angles/rotation of attached Objects

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!
__________________
First they ignore you,
Then they laugh at you,
Then they fight you,
Then you win.

- Mohandas Karamchand Gandhi.

[Tutorial] Axis and Angles/rotations of Attached Objects
[Tool/Web/Other] BSN Textdraw Editor Online
[Tool/Web/Other] BSN Image2Textdraw Converter Online
bhaveshnande is offline   Reply With Quote
Old 13/03/2011, 12:51 PM   #10
[SFA]SpiRRiT
Big Clucker
 
[SFA]SpiRRiT's Avatar
 
Join Date: Dec 2010
Location: The Netherlands
Posts: 139
Reputation: 1
Default Re: Axis and Angles/rotation of attached Objects

Awesomee!!
[SFA]SpiRRiT is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Attached Objects Disappearing GuikBretas Help Archive 1 27/02/2011 12:43 PM
[BUG] Attached objects jonrb Help Archive 3 02/12/2010 10:53 PM
Are attached objects solid? x-cutter Help Archive 5 21/02/2009 12:43 PM


All times are GMT. The time now is 01:35 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.