SetElementBoneRotation: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Improve example)
(Remove obsolete Requirements section)
 
(11 intermediate revisions by 2 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
{{Client function}}
{{Client function}}
{{New feature/item|3.0160|1.5.8|20704|This function sets the rotation of a specific bone relative to the element. Currently the following element types are accepted:
{{Added feature/item|1.5.9|1.5.8|20704|This function sets the rotation of a specific bone relative to the element. Currently the [[Element/Player|Player]] and [[Element/Ped|Ped]] element types are accepted.}}
* [[Element/Player|Player]]
{{Tip|If you want to attach an element to a bone, see [[attachElementToBone]].}}
* [[Element/Ped|Ped]]
{{Note|[[updateElementRpHAnim]] must be called after this function to apply bone rotation.}}
}}
{{Tip|If you want to attach an element to a bone, see [[attachElementToBone]]}}


==Syntax==
==Syntax==
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">
bool setElementBoneRotation ( element theElement, int bone, float yaw, float pitch, float roll )
bool setElementBoneRotation ( element theElement, int boneId, float yaw, float pitch, float roll )
</syntaxhighlight>
</syntaxhighlight>


Line 15: Line 13:


===Required Arguments===
===Required Arguments===
*'''theElement:''' the element to set the bone rotation on.
*'''theElement:''' The [[element]] to set the bone rotation on.
*'''bone:''' the ID of the bone to set the rotation of. See [[Bone IDs]]
*'''boneId:''' The ID of the bone to set the rotation of. See [[Bone IDs]].
*'''yaw:''' the 'yaw' rotation value.
*'''yaw:''' The yaw rotation value.
*'''pitch:''' the 'pitch' rotation value.
*'''pitch:''' The pitch rotation value.
*'''roll:''' the 'roll' rotation value.
*'''roll:''' The roll rotation value.


===Returns===
===Returns===
Returns ''true'' if the function was successful, ''false'' otherwise.
Returns ''true'' if the function was successful, ''false'' otherwise.
'''Note:''' [[updateElementRpHAnim]] must be called after this function to apply bone rotation.


==Example==
==Example==
This example shows how you can turn a local player into a so-called 'Helicopter'.
This example shows how you can turn a local player into a so-called 'Helicopter':
<syntaxhighlight lang="lua">local custom_yaw = 0
<syntaxhighlight lang="lua">
local customYaw = 0
local shoulders = {22, 32}


setTimer(function()
setTimer (function ()
     custom_yaw = custom_yaw + 20
     customYaw = customYaw + 20
end, 10, 0)
end, 10, 0)


local shoulders = {22, 32}
function changeBoneRotation ()
    local yaw, pitch, roll = getElementBoneRotation (localPlayer, 2) -- Get the element's bone rotation
    setElementBoneRotation(localPlayer, 2, customYaw, pitch, roll) -- Set the elements' bone rotation with custom yaw


function changeBoneRotation()
     for key, value in pairs (shoulders) do
    local yaw, pitch, roll = getElementBoneRotation(localPlayer, 2)
       setElementBoneRotation(localPlayer, value, 0, 0, 0) -- Update the ped's shoulders rotation
    setElementBoneRotation(localPlayer, 2, custom_yaw, pitch, roll)
     for key, value in pairs(shoulders) do
       setElementBoneRotation(localPlayer, value, 0, 0, 0)
     end
     end
     updateElementRpHAnim(localPlayer)
     updateElementRpHAnim(localPlayer) -- Update the ped's bone animations
end
end
addEventHandler("onClientPedsProcessed", getRootElement(), changeBoneRotation)
 
addEventHandler ("onClientPedsProcessed", getRootElement(), changeBoneRotation)
</syntaxhighlight>
</syntaxhighlight>


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

Latest revision as of 17:24, 7 November 2024

This function sets the rotation of a specific bone relative to the element. 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=|]] Note: updateElementRpHAnim must be called after this function to apply bone rotation.

Syntax

bool setElementBoneRotation ( element theElement, int boneId, float yaw, float pitch, float roll )
Rotation axes

Required Arguments

  • theElement: The element to set the bone rotation on.
  • boneId: The ID of the bone to set the rotation of. See Bone IDs.
  • yaw: The yaw rotation value.
  • pitch: The pitch rotation value.
  • roll: The roll rotation value.

Returns

Returns true if the function was successful, false otherwise.

Example

This example shows how you can turn a local player into a so-called 'Helicopter':

local customYaw = 0
local shoulders = {22, 32}

setTimer (function ()
    customYaw = customYaw + 20
end, 10, 0)

function changeBoneRotation ()
    local yaw, pitch, roll = getElementBoneRotation (localPlayer, 2) -- Get the element's bone rotation
    setElementBoneRotation(localPlayer, 2, customYaw, pitch, roll) -- Set the elements' bone rotation with custom yaw

    for key, value in pairs (shoulders) do
       setElementBoneRotation(localPlayer, value, 0, 0, 0) -- Update the ped's shoulders rotation
    end
    updateElementRpHAnim(localPlayer) -- Update the ped's bone animations
end

addEventHandler ("onClientPedsProcessed", getRootElement(), changeBoneRotation)

See Also