local Position, Size = SomeCharacter:GetBoundingBox()
local Floor = Position.Position-Vector3.new(0, Size.Y*0.5, 0)
Do I really need :GetBoundingBox()
or is their a cleaner way?
local Position, Size = SomeCharacter:GetBoundingBox()
local Floor = Position.Position-Vector3.new(0, Size.Y*0.5, 0)
Do I really need :GetBoundingBox()
or is their a cleaner way?
If there is a humanoid attached you can try:
local pos = SomeCharacter.PrimaryPart.Position-Vector3.new(0, SomeCharacter.PrimaryPart.Size.Y/2+SomeCharacter.Humanoid.HipHeight, 0)
Although I don’t know the specifics, I would assume this is faster than GetBoundingBox
, but you will have to see if its accurate enough for your purposes. I got about a 0.00177 difference.
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character
local position = character.HumanoidRootPart.Position
local floorPos = position - Vector3.new(0, 3, 0)
The character is raised to a height of 3 studs from the floor.
What if they have a different body type?
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character
local position = character.HumanoidRootPart.Position
local posY = character.HumanoidRootPart.Position.Y
local floorPos = position - Vector3.new(0, posY, 0)
Then the height will just be 0
Im not 100% sure what you mean by that but assuming you’re looking for the position of the floor underneath the player, you can create a ray that goes downwards from the player and use that to calculate the distance.
local players = game:GetService("Players")
local player = players.LocalPlayer
repeat wait()
until player.Character
local character = player.Character
local humanoidHeightScale = character.Humanoid.BodyHeightScale.Value
local scaleY = 3*humanoidHeightScale
local charPosX = character.HumanoidRootPart.Position.X
local charPosY = character.HumanoidRootPart.Position.Y
local charPosZ = character.HumanoidRootPart.Position.Z
local charFloorPosY = charPosY - 3.15
charFloorPosY = (math.round(charFloorPosY * 100))/100
local charFloorPos = {X = charPosX, Y = charFloorPosY, Z = charPosZ}
print(charFloorPos.X, charFloorPos.Y, charFloorPos.Z)
I tried working with a Vector3 instance instead but it would have a Y value with an extremely small decimal part. I tried to round this but it isn’t possible to explicitly assign values to the properties of a Vector3 instance. Nevertheless the above implementation works & does provide the accurate floor position for any character of any scale.
local players = game:GetService("Players")
local player = players.LocalPlayer
repeat wait()
until player.Character
local character = player.Character
local humanoidHeightScale = character.Humanoid.BodyHeightScale.Value
local scaleY = 3*humanoidHeightScale
local charPos = character.HumanoidRootPart.Position
local changeY = Vector3.new(0, scaleY, 0)
local charFloorPos = charPos - changeY
print(charFloorPos)
This was the version which produces Vector3 instances with very small decimal parts (this is a common issue with Vector3 instances).
Here’s a code that can help.
The script may be different depending if it was in the player or in the part(floor). For this example i’m going to use a script inside the player (because I feel like it’s easier to detect the floor’s position).
script.Parent.Touched:Connect(function(floor)
if floor.Name == “Floor” then
~insert the changing size script or what ever you want here~
end
end)
This is just a guide to detect when the player is touching a floor. Hope this helps.
This does not work for R6 rigs though