Character morph into custom avatar

I’m working on a server script that morphs a player’s character when they step on a part. Sometimes the morph results in the new character’s legs clipping through the ground.
MorphClip MorphNoClip

The only difference in the source code for the two images is the humanoid:ApplyDescription() call being commented out or not. I was attempting to use the HumanoidDescription to remove all accessories. I removed the code that set those values for testing and only applied back the description retrieved using humanoid:GetAppliedDescription(). Applying the HumanoidDescription before / after replacing parts with humanoid:ReplaceBodyPartR15() didn’t change the behavior.

I didn’t performing the morph using the Body Parts values in HumanoidDescription. I wasn’t sure how to get my morph model into a bundle / asset / whatever the correct terminology is. As you probably guessed, I’m completely new to Roblox development :slight_smile:

Any help / advice is appreciated.

Code for the function connected to the morph part:

local function morphToGorilla(otherPart)
	local otherPartParent = otherPart.Parent
	local humanoid = otherPartParent:FindFirstChildWhichIsA("Humanoid")
	if humanoid then
		local character = humanoid.Parent
		local player = Players:GetPlayerFromCharacter(character)
		if player then
			if _debounceTable[player.UserId] then
				return
			end

			_debounceTable[player.UserId] = {}

			local defaultHumanoidDescription = humanoid:GetAppliedDescription()
			--humanoid:ApplyDescription(defaultHumanoidDescription) -- Causes Clip

			local gorillaTemplateClone = Workspace.randuRigs.GorillaTemplate:Clone()

			local r15PartsToReplace = {
				Head =  gorillaTemplateClone.Head,
				UpperTorso = gorillaTemplateClone.UpperTorso,
				LowerTorso = gorillaTemplateClone.LowerTorso,
				LeftUpperArm = gorillaTemplateClone.LeftUpperArm,
				LeftLowerArm = gorillaTemplateClone.LeftLowerArm,
				LeftHand = gorillaTemplateClone.LeftHand,
				RightUpperArm = gorillaTemplateClone.RightUpperArm,
				RightLowerArm = gorillaTemplateClone.RightLowerArm,
				RightHand = gorillaTemplateClone.RightHand,
				LeftUpperLeg = gorillaTemplateClone.LeftUpperLeg,
				LeftLowerLeg = gorillaTemplateClone.LeftLowerLeg,
				LeftFoot = gorillaTemplateClone.LeftFoot,
				RightUpperLeg = gorillaTemplateClone.RightUpperLeg,
				RightLowerLeg = gorillaTemplateClone.RightLowerLeg,
				RightFoot = gorillaTemplateClone.RightFoot,
			}

			for _, BodyPart in pairs(character:GetChildren()) do
				if (BodyPart:IsA("BasePart")) then
					local EnumBodyPartR15 = humanoid:GetBodyPartR15(BodyPart)

					local EnumBodyPartR15String = tostring(EnumBodyPartR15):match("%.(%w+)$")

					if (r15PartsToReplace[EnumBodyPartR15String]) then

						local NewBodyPart = r15PartsToReplace[EnumBodyPartR15String]
						NewBodyPart.Anchored = false
						NewBodyPart.Parent = BodyPart.Parent

						humanoid:ReplaceBodyPartR15(EnumBodyPartR15, NewBodyPart)
					end
				end
			end

			wait(2)
			_debounceTable[player.UserId] = nil
		end
    end
end
2 Likes

Perhaps setting Humanoid.HipHeight could fix the mesh clipping into the ground? Let me know if this fixes it, if not maybe we can figure something else out.

They Vrythex, thanks for the reply.

I printed the HipHeight for both cases and the value is the same.
NoClip - HipHeight 4.177520275116
Cliping - HipHeight 4.177520275116

I had been trying to avoid manually updating the HipHeight value because I had read that it is automatically calculated. I went ahead and tried to play around with that a bit and it looks like there may be some issue with the way I’m using ApplyDescription and ReplaceBodyPartR15. If I have a delay between applying the description and replacing the body parts, there is no clipping issue.

I started looking at GetPropertyChangedSignal to use on the HipHeight so I could replace the body parts and then apply the HumanoidDescription after the new HipHeight was calculated. That event fired off a fair number of times during the body part swap (maybe 15ish). I don’t really want to re-apply the description that many times.

I’m thinking maybe just using the HumanoidDescription for replacing the body parts as well might avoid this issue. Also it appears to me that HumanoidDescription is somewhat of a newer interface so it might be best to use it.

Now I just need to figure out how to get my custom avatar model into some kind of format that the HumanoidDescription can use.

1 Like

Interesting, I didn’t realize HipHeight was automatically calculated. When you refer to the mesh clipping into the ground, is the character stuck in the ground? Or can you move around as your new character, but the character’s feet appear in the ground?

EDIT: While I’m not sure what is causing the issue specifically, you may have come across the solution in your reply to me. On another note, as I was looking back at your first post I noticed that you were trying to remove accessories from the character. Perhaps you could manually remove accessories using a loop? GetChildren() and IsA() may help with this. Then you could continue using humanoid:ReplaceBodyPartR15().

The character could still move, just the lower legs / feet clipped into the ground. The HipHeight calculation is discussed in the below post.
https://devforum.roblox.com/t/humanoidrootpart-positioning-adjustment-for-automatically-scaled-humanoids/258555

I didn’t replace the RootPart so I was thinking maybe the Player’s original RootPart position was causing the HipHeight to be off. That doesn’t appear to be the case because the HIpHeight is the same value regardless of the clipping issue.

Maybe I’m running into the " Changing the assets on a character while also using the HumanoidDescription system could lead to undefined behavior" warning described in the HumanoidDescription System article and that is causing the clipping.
humanoiddescription-system

I’d like to use the HumanoidDescription (HD) to do the morph if possible. I saved off the parts associated with the LeftArm (LeftHand, LowerLeftArm, UpperLeftArm) and attempted to set that using a HD. It updated the size of the arm, but the Mesh didn’t get applied. I’m using a Mesh a friend uploaded and now I think I might be running into an issue described in:
https://devforum.roblox.com/t/humanoiddescriptions-is-there-anyway-to-use-custom-assets-not-owned-by-you/239721

I was able to use Player:ClearCharacterAppearance to remove most of the accessories. It says that doen’t apply to t-shirt or face so I can just manually clear those out.

Thanks for the ideas!

Awesome! It sounds you’ve discovered the direction you need go in. Thinking back on how you mentioned:

it sounds like the issue may have been caused by using both at the same time, as you mentioned. But then again it’s hard to be positive on that. Perhaps someone who is more familiar with how the functions work can weigh in. Good luck on your script!