Finding part underneath player

I want to make a system that finds if the player is standing in a “Grass” part. However, when I try to downcast (raycast downwards), the part being returned is not the part that is beneath the player. It is usually a part that is to the side of the player

This is my current code:

local function getGround()
		local char = player.Character or player.CharacterAdded:Wait()
		local hrp = char:WaitForChild('HumanoidRootPart')
		local rp = RaycastParams.new()
		rp.FilterDescendantsInstances = {char}
		rp.FilterType = Enum.RaycastFilterType.Blacklist
		rp.IgnoreWater = true
		local rr = workspace:Raycast(hrp.Position, hrp.Position-Vector3.new(0, 10, 0), rp)
		if not rr then return false end
		if rr.Instance then
			print(rr.Instance:GetFullName())
			if rr.Instance.Parent.Name == 'Grass' and rr.Instance.Name == 'Grass' then
				return true
			end
		end
		return false
	end

I tried setting the Y value of the Vector3 to a higher value but that resolved nothing. Thanks in advance!

Maybe try

local rr = workspace:Raycast(hrp.Position, hrp.CFrame.UpVector * -10, rp)

So it will raycast downwards

3 Likes

In the middle of trying this i thought maybe the grass blocks were too high for the ray to count them, so i moved them down and it worked so that must have been the problem. Sorry for wasting your time and thanks anyway!

1 Like

Least you eventually found the answer! I would recommend using The UpVector and multiplying it by -10 as opposed to how you do it, but it’s personal preference in the end! If you have anymore issues don’t be afraid to make another post!

1 Like