How do I find where the ground is at?

I have this script, but it’s not accurate, even if the player is on the ground, the ground is detected like 3-4 studs above.

local function findGround()
		local raycastParams = RaycastParams.new()
		
		raycastParams.FilterType = Enum.RaycastFilterType.Include
		raycastParams.FilterDescendantsInstances = {workspace.InvisibleMapBarriers}

		local rootPart_p: Vector3 = plr.Character.HumanoidRootPart.Position

		local raycast = workspace:Raycast(rootPart_p, Vector3.new(rootPart_p.X, rootPart_p.Y - 1000000, rootPart_p.Z), raycastParams)
		local raycast_p = raycast.Position

		return raycast_p.Y
	end
1 Like

Is the ground a part?


Yes I have 0 terrain in my game.

So you want to know where the very top of the part is?

Why don’t you just use HumanoidState??

1 Like

Yes I want to know where the ray that originated from the player’s HRP touched the ground, and I want to return the Y.

Because I’m not trying to see if the player is grounded, but rather I’m trying to get the ground level of the player.

Maybe you could try getting the part that was hit by the raycast and then get the part’s position

Why are you using Enum.RaycastFilterType.Include instead of Enum.RaycastFilterType.Exclude? Also, like mentioned above, add the player’s character to the table.

No it won’t because the filter type is include and it includes workspace.InvisibleMapBarriers

Because the ground is only in the one workspace.InvisibleMapBarriers

Fixed it by adding workspace.Map to the FilterDescendantsInstances.

3 Likes

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