Set Model Question for entities

I’m creating a custom entity, I use the following in the “ENT:Initialize()” function:


It works, the model is set, it appears like so in game:

My only problem is, I don’t want it to have the T-POSE, I want it to have a normal looking pose, with it’s arms down.

I don’t really care weather or not it has the animations, as long as the pose it right, It’s all good.

I’ve tried looking on the wiki, but I can’t get the google cache page to load for help with animations, and the backup wiki is just hopeless. I’ve also tried facepunch search and google search – No luck…

You’ll have to loop through each bone of the ragdoll and set their angles and positions manually. There’s a simple way of doing it though. Spawn a combine soldier, make sure they’re in the pose you want, then run this on it:

bones = combine:GetPhysicsObjectCount()
for i=0,bones do
    local ragbone, combone = ragdoll:GetPhysicsObjectNum(i), combine:GetPhysicsObjectNum(i)

Where combine is the combine you spawned, and ragdoll is the model you’re posing. I’m not 100% sure the code will work though, since the combine is an NPC, and not necessarily a ragdoll…

Alternatively, this code might work (and even be better):

bones = combine:GetBoneCount()
for i=0,bones do
    ragdoll:SetBonePosition(i, combine:GetBonePosition(i))

A note on the wiki says SetBonePosition only works inside a clientside hook though (ENT:BuildBonePositions), so you might wanna put that inside the hook for the entity you’re posing.

Lastly, if that doesn’t work either, you can use this:

bones = combine:GetBoneCount()
for i=0,bones do
    local bone = ragdoll:GetPhysicsObjectNum(combine:TranslateBoneToPhysBone(i))
    local pos, ang = combine:GetBonePosition(bone)

Still not 100% sure if it’ll work though. Try it.

EDIT: Oh yeah, it’s a bad idea to spawn combines every frame. Should’ve mentioned that. Just spawn one and store the info for the pose you want in the script or something. You can print the variables in a table with PrintTable(<table>), so then you can just manually write them into the script as variables without ever having to spawn a combine again.

Thanks, that helps a lot :stuck_out_tongue:

Come to think of it, you may also want to use positions that are local to the entity. Just use the combine:WorldToLocal on the positions fetched from the combine, and ragdoll:LocalToWorld when you set the positions for the ragdoll’s bones. Ask if you want more explanation on how.

Why not just set the animation for the entity?

Please explain how to (I couldn’t access this page on the wiki)

That’s the wiki page. I’m not sure if it works on non-NPCs though. If it does, it’s better than any of my suggestions.

I actually couldn’t get any of these suggestions to work, I changed the model, and then they started to work, maybe they just don’t work with that combine model I tried >_>

Thanks all :stuck_out_tongue:

It might be that the bone indexes start on 1 instead of 0. If that’s the case, the code I wrote won’t work. Just make “i” start with 1 in the for loop and it should work (if that’s the problem, that is). Also, try to make sure that the reference combine has the same model as the entity model.

The simplest solution was the easiest – I worked out that there are two different rag doll models, one with /player/ in it, and one without, the ones without default to the idle animation I wanted :smiley: