I'm trying to make some sort of shared ragdoll for the player so both the client and server sees the same ragdoll but SetBonePosition is clientside only for some reason so the closest I can get is spawning it in a T-pose. ManipulateBoneAngles/Position streches out the model like crazy. I have also tried using bonemerge and then un-parenting the ragdoll from the player which works fine but the ragdoll spazzes out and does a backflip or something like that when it spawns.
Is there really no serverside SetBonePosition or other some other way to fix this?
ply:CreateRagdoll()
ply.Ragdoll = ents.Create("prop_ragdoll")
ply.Ragdoll:SetOwner(ply)
ply.Ragdoll:SetModel(ply:GetModel())
ply.Ragdoll:SetPos(ply:GetRagdollEntity():GetPos())
ply.Ragdoll:Spawn()
for i=0,ply:GetBoneCount()-1 do
local pos, ang = ply:GetRagdollEntity():GetBonePosition( i )
ply.Ragdoll:SetBonePosition(i,pos)
end
ply:GetRagdollEntity():Remove()
Here you go:
local bones = rag:GetPhysicsObjectCount()
for i = 0, bones - 1 do
local name = rag:GetBoneName(rag:TranslatePhysBoneToBone(i))
local tBone = self:LookupBone(name)
if(tBone != nil) then
local bonePos, boneAng = self:GetBonePosition(tBone)
local bonePos = WorldToLocal(bonePos, boneAng, self:GetPos(), Angle(0,0,0))
local bone = rag:GetPhysicsObjectNum(i)
bone:SetPos(self:LocalToWorld(bonePos))
bone:SetAngles(boneAng)
end
end
Time to explain:
The easiest way to view a ragdoll is to think of it as a bunch of props attached together with ropes, and the "props" are the parts of the body such as arms, legs and head. Problem is that you can't have one for every bone in a ragdoll because that would be a lot of physics going on, a normal ragdoll has around 50 bones if I remember correctly. So what we have here are called Physics Bones (Small bones such as fingers and attachments are useless to us so they have no physics) and they are "normal" entities like any other prop, with their own physics object and so we can apply force on them or set their position. To find all of the physic bones a ragdoll has (They are all related to each other and they are all the same ragdoll, think of it like Father, Son and the Holy Spirit being different things but all being God at once) we just use the function GetPhysicsObjectCount() and GetPhysicsObjectNum(). Now to find the position the physics bone is supposed to be we find the normal bone on the body by using TranslatePhysBoneToBone which will give us the ID of it. I'm not sure why I translated the position to local coordinates then translated it again to world coordinates but I guess you can understand the rest, we simply use SetPos and SetAngles because it's used on the physics bones.
Already figured it out, thanks anyways!
Sorry, you need to Log In to post a reply to this thread.