How to get the Height of a R15 Character

I have here a script that sets the height of a Attachment to the floor depending on the character’s height. The code works, but I couldn’t get it to the Floor itself, its stuck midway my legs.

PLAYERS.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(chr)
		if plr:GetRankInGroup(GROUP_ID) == 6 or MPS:UserOwnsGamePassAsync(plr.UserId, VIP_ID) then
			local HRP		=	chr:WaitForChild("HumanoidRootPart")
			local HUM		=	chr:WaitForChild("Humanoid")
			local FOOT		=	chr:WaitForChild("RightFoot") or chr:WaitForChild("Right Leg")
			local CLONE		=	VIP_BOOSTER:Clone()
			
			for i, v in pairs(CLONE:GetChildren()) do
				v.Parent = HRP
				if v.Name	== "Aura_Bottom" then
					local offset 	=	HUM.HipHeight + (HRP.Size.Y/2)
					offset = offset - (v.Position.Y/2)
					print(offset)
				end
			end
		end		
	end)
end)

image
This should be stretched and touching the floor…

2 Likes

According to the documentation for Humanoid.HipHeight:

The overall height of the humanoid can be described in the following formula:

Height = (0.5 * RootPart.Size.Y) + HipHeight

*It seems like that’s already being done in the offset variable in the code you posted, though, so maybe the calculation that was made afterwards is causing the discrepancy?

3 Likes

The code is working, however I can’t seem to detect the Attachment’s Y position and whenever I check the Model, its set to the standard size. But whenever it prints, the code actually works.

3 Likes

Ah, I see. After looking back at the code, it seems like the issue might just be that the offset was never applied to the Attachment.

The code only defines the offset given the height of the Character (and updates it once more afterwards) but from that point onward, the variable is never used to update any properties of the Attachment afterwards, which is why it’s printing the correct value but nothing is changing on the Character model itself:

1 Like
offset = offset - (v.Position.Y/2)

This is the Code I believe is not working properly, and I think I need to use CFrame, can you help me out with this one, I’m not really fond of Math when it comes to LUA :sob:

1 Like

Just do:

character:GetExtentsSize().Y

It retuns the exact size of your model in studs.

3 Likes

ooo, how would I be able to use this in the script? oh and btw, I’m trying to put the value to the Attachment Position

1 Like

The offset looks like it was calculated correctly, so that part probably isn’t the issue. You need to use the value afterwards to update the position of the Attachment (e.g. v.Position = offset, *or in this case, it would likely be v.Position = Vector3.new(v.Position.X, offset, v.Position.Z), but my brain is a bit fried right now so maybe I am incorrect haha), since right now, the script is figuring out the necessary offset to make it appear in the correct spot but it’s not changing where the Attachment is positioned.

3 Likes

Just paste that code in the script? It’s not too hard. It’s more accurate than whatever you two have been calculating here and overall better.

well its not just the overall height I’m trying to get from the Character itself, I’m trying to get the position of the HumanoidRootPart to the Floor itself so I can place the Attachment at the Bottom Floor.

and yes, this actually works I forgot to set the Value itself to the attachment- holy :sob:

1 Like

I see, then do:

local Height = character:GetExtentsSize().Y

local HumanoidRootPartCFrame = character.HumanoidRootPart.CFrame

local BottomPosition = (HumanoidRootPartCFrame * CFrame.new(0,Height/2,0)).Position
2 Likes

This will be offset when the character is wearing an accessory that goes past the character’s feet, you should use the HipHeight option

1 Like

No not really, I just tested it out with various rigs and it works flawlessly and does get the accurate position of the player’s floor.

Alternatively, one can also use rayCasts!

local params = RaycastParams.new()
params.FilterDescendantInstances = {character}
local ray = workspace:RayCast(HumanoidRootPart.Position,Vector3.yAxis*-Height/2,params)

print(ray.Position)
1 Like

your solution can be used as an easy alternatives, but right now the code I got help with @StrongBigeMan9 worked flawlessly and I tried it with various character sizes that I have (plushie ava, tall ava, normal ava, etc)

2 Likes

Okay then mark theirs as the solution? I am just here to provide an easier alternative to the post. If their post helped you then it’s good, mark theirs as solution.