- Documentation
- Client functions
- getPedBoneMatrix
Function
getPedBoneMatrix
Returns a ped bone's 4x4 matrix for this frame, in the same layout as getElementMatrix: row 1 = the bone's X axis, 2 = Y axis, 3 = Z axis, 4 = position. These are the same axes in which attachElementToBone applies its offset and rotation, so the attach point is position + X*dx + Y*dy + Z*dz. It is computed straight from the bone rotation in the engine, without Euler angles, so it keeps its precision at 90° turns.
Syntax
table getPedBoneMatrix(ped thePed, int bone)Arguments
thePedped- The ped (streamed in).
boneint- Bone number (
getBoneIDs).
Returns
The matrix { {xx,xy,xz,0}, {yx,yy,yz,0}, {zx,zy,zz,0}, {x,y,z,1} } or false.
Example
addEventHandler("onClientPedsProcessed", root, function()
local m = getPedBoneMatrix(localPlayer, 25) -- prawa dłoń
if not m then return end
-- punkt 20 cm wzdłuż osi X dłoni
local x, y, z = m[4][1] + m[1][1] * 0.2, m[4][2] + m[1][2] * 0.2, m[4][3] + m[1][3] * 0.2
dxDrawLine3D(m[4][1], m[4][2], m[4][3], x, y, z, tocolor(255, 0, 0), 2)
end)
Notes
The freshest bone positions are in onClientPedsProcessed (after this frame's animation update).
See also
getPedBonePositionReturns the world position of a chosen skeleton bone of a ped, such as the head or a hand. On the client the position is exact and follows the animation (the bone is read from the game). The server does not know the ped's pose, so it returns an approximation: a fixed bone offset of a standing ped, rotated to match its heading. Bone numbers are the ones fromgetBoneIDs(e.g. 8 head, 25 right hand, 35 left hand); on the client a game bone index also works.getPedBoneRotationReturns the world rotation of a chosen skeleton bone of a ped, in degrees, exactly as it looks in the current animation frame. Works for peds visible in this game. Useful for attaching objects to a hand or the head so they rotate with it.attachElementToBoneAttaches an element (e.g. an object) to a ped's bone, with an offset and rotation. The element moves with the bone, e.g. a hat with the head or a weapon in a hand. Bone numbers are the same as ingetBoneIDs(e.g. 1 pelvis, 8 head, 25 right hand, 35 left hand).getElementMatrixReturns the element's matrix (position and rotation). By default a 4x4 table; withlegacy = falseaMatrixobject.