SetElementBoneQuaternion: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
(Undo revision 80611 by Nico834 (talk))
Tag: Undo
Line 6: Line 6:
The use of [https://en.wikipedia.org/wiki/Quaternion quaternions] are more effective and do not generate issues like gimbal lock that might arise with [https://en.wikipedia.org/wiki/Euler_angles Euler angles], so they are a preferable choice for rotation.
The use of [https://en.wikipedia.org/wiki/Quaternion quaternions] are more effective and do not generate issues like gimbal lock that might arise with [https://en.wikipedia.org/wiki/Euler_angles Euler angles], so they are a preferable choice for rotation.
}}
}}
{| class="wikitable"
|-
! scope="col"| ×
! scope="col"| 1
! scope="col"| i
! scope="col"| j
! scope="col"| k
|-
! scope="row"| 1
| 1
| i
| j
| k
|-
! scope="row"| i
| i
| -1
| k
| -j
|-
! scope="row"| j
| j
| -k
| -1
| i
|-
! scope="row"| k
| k
| j
| -i
| -1
!colspan="5"|Shopping List
|}


{{Tip|If you want to attach an element to a bone, see [[attachElementToBone]].}}
{{Tip|If you want to attach an element to a bone, see [[attachElementToBone]].}}

Revision as of 04:02, 30 September 2024

ADDED/UPDATED IN VERSION 1.6.0 r22722:

This function determines 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.


[[{{{image}}}|link=|]] Tip: If you want to attach an element to a bone, see attachElementToBone.
[[{{{image}}}|link=|]] Note: If you want to apply the rotation, updateElementRpHAnim must be called after this function.

Syntax

bool setElementBoneQuaternion(element ped, int bone, float x, float y, float z, float w)

Required Arguments

  • ped: The element (ped or player) on which the bone's rotation will be set.
  • bone: The ID of the bone to set 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.
  • x: The quaternion's coefficient of the 𝑖 component.
  • This represents the rotation around the x-axis and is the first imaginary part of the quaternion.
  • y: The quaternion's coefficient of the 𝑗 component.
  • This represents the rotation around the y-axis and is the second imaginary part of the quaternion.
  • z: The quaternion's coefficient of the 𝑘 component.
  • This represents the rotation around the z-axis and is the third imaginary part of the quaternion.
  • w: The real part of the quaternion.
  • This denotes the scalar component of the quaternion, which is linked to the angle of rotation.
  • The w value is derived by taking the cosine of half of the rotation angle, defined as the overall angle of rotation.

Returns

Returns true if the set was successful, otherwise returns an error message and returns false.

Example

This example rotates the player's pelvis 180 degrees around an arbitrary axis.
The use of updateElementRpHAnim is necessary here as it applies the rotation.

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

addEventHandler("onClientPedsProcessed", root,
    function()
        setElementBoneQuaternion(localPlayer, playerBone, playerBoneX, playerBoneY, playerBoneZ, playerBoneW)
        updateElementRpHAnim(localPlayer)
    end
)

Requirements

This template will be deleted.

See Also