GetElementBoneMatrix

From Multi Theft Auto: Wiki
Revision as of 20:25, 12 December 2023 by 1Lorenzo (talk | contribs) (→‎Example)
Jump to navigation Jump to search

This function returns the transformation matrix of a specific bone. Currently the Player and Ped element types are accepted.

[[{{{image}}}|link=|]] Tip: If you want to attach an element to a bone, see attachElementToBone.
[[{{{image}}}|link=|]] Tip: For matrix manipulation which goes beyond the basic examples given on this page, see the Lua matrix library. Using the built-in matrix class is also recommended.

Syntax

table getElementBoneMatrix ( element theElement, int boneId )

Required Arguments

  • theElement: the element to get the bone matrix on.
  • boneId: the ID of the bone to get the matrix of. See Bone IDs.

Returns

Returns a multi-dimensional array (which can be transformed into a proper matrix class using Matrix.create method) containing a 4x4 matrix. Returns false if invalid arguments were passed.

Example

this example will output bone position and rotation for id 5.

local boneMatrix = getElementBoneMatrix(localPlayer, 5) -- get the bone matrix for localPlayer, id: 5
if boneMatrix then
    -- extract position and rotation from the matrix
    local posX, posY, posZ = boneMatrix[4][1], boneMatrix[4][2], boneMatrix[4][3]
    local rotX, rotY, rotZ = math.deg(math.asin(-boneMatrix[3][2])), math.deg(math.atan2(boneMatrix[3][1], boneMatrix[3][3])), math.deg(math.atan2(boneMatrix[1][2], boneMatrix[2][2]))

    outputChatBox("Bone position: (" .. posX .. ", " .. posY .. ", " .. posZ .. ")")
    outputChatBox("Bone rotation: (" .. rotX .. ", " .. rotY .. ", " .. rotZ .. ")")
else
    outputChatBox("Invalid element or bone ID.")
end

Requirements

This template will be deleted.

See Also