My AlignMorphOnPlayer function is not working correctly

I have a morph system in a game that works by making the player transparent and welding a model to the humanoid.rootpart. This function AlignMorphOnPlayer purpose is to return a cframe aligning the morph on the players character so that it can be welded.

The issue is each morph is a different size and I am having trouble with some morphs floating slightly and others lower than the ground. Some look perfect. I have tried to approach it different ways and still come up with the same result. I have search the forums, the web and even tried to have AI help.

My hopes are someone here can point me in the right direction.
TIA

local function AlignMorphOnPlayerME(character:model, morph:model)
	
	local _, size = character:GetBoundingBox()
	local _, size2 = morph:GetBoundingBox()

	local YDiff = size.Y - size2.Y
	
	local newPosition = Vector3.new(
		character.PrimaryPart.CFrame.Position.X, 
		character.PrimaryPart.Position.Y - (YDiff / 2), 
		character.PrimaryPart.CFrame.Position.Z
	)

	local _, orientation, _ = character.PrimaryPart.CFrame:ToOrientation()
	local newCFrame = CFrame.new(newPosition) * CFrame.Angles(0, orientation, 0)

	

	return newCFrame
end

You can change the hipHeight of the humanoid to prevent morphs from floating or going underground

Considering every player can have a different height do you mean by script? And change it to what? zero? I suppose I need to go read about hip height and what its role is.

The game is a “Find the X” style and you have the option of morphing into the item when you find it. It must be done dynamically by comparing the player model and morph model size in the world. I will check out hip height and try to incorporate it into the formula.

Ohh i see, then your method should prob work out but
i think the formula for the y pos might be the problem, instead of subtracting it by yDiff/2 i think it should be subtracted by just yDiff or added by yDiff

yes it is the yDiff, I have tried all them ways and some others also. Its not terrible right now but it is off by almost 1.5 studs in some morphs and others by almost nothing. -(ydiff/2) was the best out of using just -yDiff or +yDiff

1 Like