Bonemerging ragdoll to animated prop makes it's hands and feet revert to origin.
1 replies, posted
When I bonemerge a ragdoll to an animated props it makes it's hands and feet revert to 0,0,0. Why does it do this, and more importantly how can I fix this?
My code is
-- these are ripped from death animations
local function TransferBones( base, ragdoll ) -- Transfers the bones of one entity to a ragdoll's physics bones (modified version of some of RobotBoy655's code)
if !IsValid( base ) or !IsValid( ragdoll ) then return end
for i = 0, ragdoll:GetPhysicsObjectCount() - 1 do
local physbone = ragdoll:GetPhysicsObjectNum( i )
if ( IsValid( physbone ) ) then
local pos, ang = base:GetBonePosition( ragdoll:TranslatePhysBoneToBone( i ) )
if ( pos ) then physbone:SetPos( pos, true ) end
if ( ang ) then physbone:SetAngles( ang, true ) end
end
end
end
local function AllowBoneMovement( ragdoll, bool ) -- Changes whether ragdolls can move
if !IsValid( ragdoll ) then return end
for i = 0, ragdoll:GetPhysicsObjectCount() - 1 do
local bone = ragdoll:GetPhysicsObjectNum( i )
if ( IsValid( bone ) ) then
bone:EnableMotion( bool )
end
end
end
function playTakeoverAnimation(wakerag)
//AllowBoneMovement(wakerag, false)
if !IsValid(wakerag) then return end
if !headCrabsPlus.CheckHead(wakerag.HCP_boneMerge) then print("Failed CheckHead test. Aborting animation") return end
wakerag:SetNoDraw(true)
wakerag.HCP_boneMerge:SetNoDraw(true)
local anibody = ents.Create("base_gmodentity")
anibody:SetModel("models/humans/male_ss.mdl")
anibody:SetPos(wakerag:GetPos() - Vector(0,80,0))
anibody:SetAngles(wakerag:GetAngles())
anibody:SetColor(Color(255,255,255,0))
anibody:Spawn()
anibody:SetNoDraw(true)
local plrModel = headCrabsPlus.CreateBoneMerge(anibody, wakerag.HCP_boneMerge:GetModel(), wakerag.HCP_boneMerge:GetSkin(), true, true)
if wakerag.HCP_boneMerge:GetPlayerColor() then
plrModel:SetPlayerColor(wakerag.HCP_boneMerge:GetPlayerColor())
end
timer.Simple(0.1, function()
net.Start("LODEntity")
net.WriteEntity(plrModel)
net.Broadcast()
end)
local headpos, headang = plrModel:GetBonePosition(plrModel:LookupBone("ValveBiped.Bip01_Head1"))
local headcrab = ents.Create("prop_dynamic")
print()
if (headCrabsPlus.HeadCrabModel[wakerag:GetModel()] == "npc_headcrab") then
headcrab:SetModel("models/nova/w_headcrab.mdl")
headcrab:SetPos(headpos)
headcrab:SetAngles(headang + Angle(90, -90, 0))
headcrab:SetMoveType(MOVETYPE_NONE)
if plrModel:LookupAttachment("anim_attachment_head") ~= 0 then
headcrab:SetParent(plrModel, plrModel:LookupAttachment("anim_attachment_head"))
else
headcrab:SetParent(plrModel, plrModel:LookupAttachment("eyes"))
end
elseif headCrabsPlus.HeadCrabModel[wakerag:GetModel()] == "npc_headcrab_fast" then
headcrab:SetModel("models/headcrab.mdl")
headcrab:SetPos(headpos - Vector(0, 0, 12))
headcrab:SetMoveType(MOVETYPE_NONE)
if plrModel:LookupAttachment("anim_attachment_head") ~= 0 then
headcrab:SetParent(plrModel, plrModel:LookupAttachment("anim_attachment_head"))
else
headcrab:SetParent(plrModel, plrModel:LookupAttachment("eyes"))
end
elseif headCrabsPlus.HeadCrabModel[wakerag:GetModel()] == "npc_headcrab_black" then
headcrab:SetModel("models/headcrabblack.mdl")
headcrab:SetPos(headpos)
headcrab:SetMoveType(MOVETYPE_NONE)
if plrModel:LookupAttachment("anim_attachment_head") ~= 0 then
headcrab:SetParent(plrModel, plrModel:LookupAttachment("anim_attachment_head"))
else
headcrab:SetParent(plrModel, plrModel:LookupAttachment("eyes"))
end
end
headcrab:Spawn()
anibody:SetSequence("headcrabbed")
anibody:SetPlaybackRate(1)
anibody.AutomaticFrameAdvance = true
anibody:SetSolid(SOLID_OBB)
anibody:PhysicsInit(SOLID_OBB)
anibody:SetMoveType(MOVETYPE_FLYGRAVITY)
anibody:SetCollisionGroup(COLLISION_GROUP_DEBRIS)
anibody:PhysWake()
//TransferBones(anibody, wakerag)
timer.Simple( anibody:SequenceDuration( "headcrabbed" ), function() -- After the sequence is done, remove the animation reference
//wakerag:SetParent()
if !IsValid(wakerag) then return end
wakerag:SetPos(anibody:GetPos() + Vector(0, 0, 64))
wakerag:SetAngles(anibody:GetAngles())
if IsValid( anibody ) then anibody:Remove() end
headcrab:Remove()
wakerag:SetNoDraw(false)
wakerag.HCP_boneMerge:SetNoDraw(false)
//AllowBoneMovement( wakerag, true )
end)
end
If the entity's model that you are trying to merge the ragdoll onto does not have all the bones as the ragdoll you are merging, the missing bones will default to the map origin (0,0,0) You can't fix it, only way is to make sure the target entity has all the bones as the ragdoll
Sorry, you need to Log In to post a reply to this thread.