How do I accurately recalculate a character's hip height for r15?

Explanation of my current setup and purpose:
If you remove a limb in r15 the character doesn’t automatically calculate the hip height so instead the character just floats there. In my game there is a table saw that can cut off limbs if you touch the blade by mistake. So the function below finds what limbs are still existing and calculates the distance between them and the HRP to make a new hip height. The wait(7) is there because when the player gets cut they also ragdoll and fall at first. So if the player is ragdolled the distance of the existing limb to the HRP would be diff compared to if they were standing.

The current issue:
So everything works right except that after the 7 seconds and the player gets up they could be walking and if they are the leg could be bent. When the leg is bent, the distance is also different and so it causes the character to have a false calculated limb to HRP distance. Is there any way I can force the character stiff for an instant after the wait(7) to do the calculations then revert to normal? And this “stiff” mode that can’t be overwritten by any animations.

My code:

function recalculateHipHeight(character)
	local bottomOfHumanoidRootPart
	local bottomOfFoot
	wait(7)
	if character:FindFirstChild("HumanoidRootPart") then
		bottomOfHumanoidRootPart = character.HumanoidRootPart.Position.Y - (1/2 * character.HumanoidRootPart.Size.Y)
	end	
	if character:FindFirstChild("LeftFoot") then
		bottomOfFoot = character.LeftFoot.Position.Y - (1/2 * character.LeftFoot.Size.Y) 
	elseif character:FindFirstChild("RightFoot") then
		bottomOfFoot = character.RightFoot.Position.Y - (1/2 * character.RightFoot.Size.Y)
	elseif character:FindFirstChild("LeftLowerLeg") then
		bottomOfFoot = character.LeftLowerLeg.Position.Y - (1/2 * character.LeftLowerLeg.Size.Y)
	elseif character:FindFirstChild("RightLowerLeg") then
		bottomOfFoot = character.RightLowerLeg.Position.Y - (1/2 * character.RightLowerLeg.Size.Y)
	elseif character:FindFirstChild("LeftUpperLeg") then
		bottomOfFoot = character.LeftUpperLeg.Position.Y - (1/2 * character.LeftUpperLeg.Size.Y)
	elseif character:FindFirstChild("RightUpperLeg") then
		bottomOfFoot = character.RightUpperLeg.Position.Y - (1/2 * character.RightUpperLeg.Size.Y)
	else
		bottomOfFoot = nil
	end
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if bottomOfFoot and bottomOfHumanoidRootPart then
		local newHipHeight = bottomOfHumanoidRootPart - bottomOfFoot
		humanoid.HipHeight = newHipHeight+.1
	elseif bottomOfHumanoidRootPart then
		humanoid.HipHeight = .1
	end
	if humanoid.HipHeight <= 0 or humanoid.HipHeight > 2 then--safety guard
		recalculateHipHeight(character)
	end
end

Setting PlatformStand = true in the Player’s humanoid essentially freezes there character so they can’t move, it is like having them sit but without sitting while still also allowing physics to affect the character. It defaults the character’s arms and legs to be straight, thus giving you the “stiff” mode you want.

2 Likes

The way I found is simple.
Here’s the code I used to test it out

local newHeight = game.Workspace.Dummy:GetExtentsSize().Y - game.Workspace.Dummy.HumanoidRootPart.Size.Y - (game.Workspace.Dummy.HumanoidRootPart.Size.Y / 2) game.Workspace.Dummy.Humanoid.HipHeight = newHeight print(newHeight)
-- did the code on the command line
5 Likes