GetElementBoneQuaternion: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Add documentation)
Β 
m (Stylistic corrections)
Β 
Line 23: Line 23:
* '''z:''' The quaternion's coefficient of the π‘˜ component, representing rotation around the z-axis.
* '''z:''' The quaternion's coefficient of the π‘˜ component, representing rotation around the z-axis.
* '''w:''' The real part of the quaternion, which is linked to the angle of rotation.
* '''w:''' The real part of the quaternion, which is linked to the angle of rotation.
==Requirements==
{{Requirements|n/a|1.6.0-9.22722}}


==Example== Β 
==Example== Β 
<section name="Client" class="client" show="true">
This example retrieves the rotation of the player's head in quaternion.<br/>
This example retrieves the rotation of the player's head in quaternion.<br/>
The retrieved values ​​can be used for calculations.
The retrieved values ​​can be used for calculations.
Line 41: Line 37:
)
)
</syntaxhighlight>
</syntaxhighlight>
</section>
Β 
==Requirements==
{{Requirements|n/a|1.6.0-9.22722}}


==See Also==
==See Also==
{{Client_element_functions}}
{{Client_element_functions}}

Latest revision as of 10:18, 16 September 2024

ADDED/UPDATED IN VERSION 1.6.0 r22722:

This function retrieves how a particular bone rotates in relation to the element.
The use of quaternions are more effective and do not generate issues like gimbal lock that might arise with Euler angles, so they are a preferable choice for rotation.

Syntax

int, int, int, int getElementBoneQuaternion(element ped, int bone)

Required Arguments

  • ped: The element (ped or player) from which the bone's rotation will be retrieved.
  • bone: The ID of the bone to retrieve the quaternion of.
  • The bone ID corresponds to specific body parts like arms, legs, spine, head, etc.
  • The full list of bones is available in the Bone IDs reference.

Returns

Returns four float values:

  • x: The quaternion's coefficient of the 𝑖 component, representing rotation around the x-axis.
  • y: The quaternion's coefficient of the 𝑗 component, representing rotation around the y-axis.
  • z: The quaternion's coefficient of the π‘˜ component, representing rotation around the z-axis.
  • w: The real part of the quaternion, which is linked to the angle of rotation.

Example

This example retrieves the rotation of the player's head in quaternion.
The retrieved values ​​can be used for calculations.

local playerBone = 1
local playerBoneX, playerBoneY, playerBoneZ, playerBoneW

addEventHandler("onClientResourceStart", resourceRoot,
    function()
        playerBoneX, playerBoneY, playerBoneZ, playerBoneW = getElementBoneQuaternion(localPlayer, playerBone)
    end
)

Requirements

Minimum server version n/a
Minimum client version 1.6.0-9.22722

Note: Using this feature requires the resource to have the above minimum version declared in the meta.xml <min_mta_version> section. e.g. <min_mta_version client="1.6.0-9.22722" />

See Also