Entity:GetBonePosition
Description
Returns the position and angle of the given attachment, relative to the world.
This function can return entity's
GetPos()
instead if the entity doesn't have it's bone cache set up.
To ensure the bone position is correct use this:
local pos = ent:GetBonePosition(0)
if pos == ent:GetPos() then
pos = ent:GetBoneMatrix(0):GetTranslation()
end
This function returns the bone position from the last tick, so if your framerate is higher than the server's tickrate it may appear to lag behind if used on a fast moving entity. You can fix this by using the bone's matrix instead:
local matrix = entity:GetBoneMatrix(0)
local pos = matrix:GetTranslation()
local ang = matrix:GetAngles()
This can return garbage if a trace passed through the target bone during bone matrix access.
Issue Tracker: 3739
Issue Tracker: 3739
Arguments
1 number boneIndex
The bone index of the bone to get the position of, starting at index 0. See Entity:LookupBone.
Returns
Example
Prints positions of all bones on an entity
-- Get the first NPC on map
local ent = ents.FindByClass( "npc_*" )[ 1 ]
-- If one is found
if ( IsValid( ent ) ) then
-- For each bone
for i = 0, ent:GetBoneCount() - 1 do
-- Print the entity, bone ID and bone position
print( ent, i, ent:GetBonePosition( i ) )
end
end