Detect how far a player is from the ground

  1. What do you want to achieve? Exactly what the title says.

  2. What is the issue? I suck at all this stuff

  3. What solutions have you tried so far? I’ve searched a lot but none of them actually detect if you’re this amount studs away from the nearest part. I’ve also tried to do ray casting but its very confusing to me because I’ve never decided to learn it. I’ve also tried looking at a lot of fall damage scripts and editing them but none seemed to do much of anything.

use raycasting to get the distance (from the torso or the foot or whatever)

1 Like

You may be able to do this:

local Player = game.Players.LocalPlayer
local Mag = (Player.Character.PrimaryPart.Position - workspace.Baseplate Position).Magnitude

while wait(1) do
print(Mag)
end

Just saying that the primary part is the head

thats gonna be the position of the baseplate, not the point right under the player

raycast from the player to the bottom of a part…

What if the player has no part under them…

return nil… or you can do something else…?

if you use a raycast, the raycast result should say that it found nothing


thats what i mean btw

Well of course. I would make a counterargument but OP did not clarify what he was trying to make exactly.

Also:

" Detect how far a player is from the ground"

sure we dont know if he wants the torso or the foot distance from ground, but he obviously means right under them

Thanks for the assistance as in fact I can only read your posts. I completely needed a direct quote from the original post.

I meant what he needed to detect the distance from the ground for.

im not rlly as good as i was at scripting before but i think this helps

(also the roblox doc kinda explains it)

also mb i thought you were confused on that part

1 Like

Right,

The idea was to use the Baseplate as the Origin
I never got to finish the Code, nor did I test it prior to posting before going to my Classes,

This Should be the finished version:
StarterCharacterScripts

local Player = game.Players.LocalPlayer
local Char = script.Parent

while wait() do
	local Mag = (Char:WaitForChild("HumanoidRootPart").Position.Y - workspace.Baseplate.Position.Y)
	print(math.round(Mag*10)/10) -- Rounds so there is no decimals besides the Tenth
end

I didn’t realise how simple raycasts were but i was able to use

humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()

to detect if the player was mid-air and i would cast a ray 50 studs down. using

game.Workspace:FindPartOnRayWithIgnoreList(checkforground, {character})

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.