How do I spawn a Ragdoll in the exact same position and angles as the player?

I’m trying to create a non-moving, fully cloned ragdoll of a player’s position and angles.

Here’s what I tried:

[lua]
local ply = Entity(1)
local rag = ents.Create(“prop_physics”)
rag:SetModel(Entity(1):GetModel())
– rag:SetPos(Entity(1):GetPos())
rag:SetKeyValue( “origin”, ply:GetPos().x … " " … ply:GetPos().y … " " … ply:GetPos().z )
rag:SetAngles(Entity(1):GetAngles())

	rag:SetSolid(SOLID_NONE)
	rag:Spawn()
	rag:Activate()


	rag:SetMoveType(MOVETYPE_NONE)
	rag:SetCollisionGroup(COLLISION_GROUP_WEAPON)


	local phys = rag:GetPhysicsObject()
	if IsValid(phys) then
		phys:EnableMotion(false)
		phys:EnableGravity(false)


	end

[/lua]

The torso holds still, but the rest of the body slumps down from T-Pose when it spawns.

Should I loop through all the bones, disabling motion and setting their angles?

What do you think I need to do?

If all else fails I was thinking I could just gesture the player into T-Pose and then spawn a ragdoll in T-Pose to sync it.

Another option I considered was to make a nextbot and set the model to the players and set the same animation sequence that the player was doing, but I want to avoid this because I think it would lag the server.

Thanks for your help.

Have a look into

Player:CreateRagdoll

Player:GetRagdollEntity

Yeah you will want to manipulate the bones too. Here’s the code from TTT:

https://github.com/Facepunch/garrysmod/blob/master/garrysmod/gamemodes/terrortown/gamemode/corpse.lua#L444

A prop_physics instead of a prop_ragdoll? Why?

Just testing what would happen. Forgot to change that part back into prop_ragdoll woops. I did test this stuff on a ragdoll though.

I’ll try out your guy’s suggestions and get back to you.

Thanks for the replies.