I’m attempting to make a part hop like a player, but I’m having a lot of trouble with figuring out how to detect if the part is grounded or not.
I’ve tried detecting if #Part:GetTouchingParts() == 0, but that didn’t work right for me so I switched to raycasting. I thought this would be my solution, but I’m having difficulty with it.
Here’s a video demonstrating the issue. If I get too far from 0, 0, 0 the raycast no longer detects that the part is grounded.
Here is my current code (inside a loop detecting if space is down)
local ignore = Player.Character:GetDescendants()
table.insert(ignore, Ball)
local grounded, atPosition = workspace:FindPartOnRayWithIgnoreList(Ray.new(Ball.Position, Ball.Position - Vector3.new(0, 10, 0)), ignore)
if grounded then
print("grounded")
Ball.Velocity = Vector3.new(Ball.Velocity.X, Ball.Velocity.Y + 50, Ball.Velocity.Z)
end
I’m stumped. I tried changing the second parameter to the direction, didn’t work. I switched to using raycast instead, and this is my code to detect if the ball is on the ground or not:
local function getPlayerParts()
local parts = {}
for _,part in pairs(Player.Character:GetDescendants()) do
if part:IsA("BasePart") then
table.insert(parts, part)
end
end
return parts
end
local function grounded()
local blacklistedParts = getPlayerParts()
table.insert(blacklistedParts, Ball)
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Blacklist
params.FilterDescendantsInstances = blacklistedParts
local ray = workspace:Raycast(Ball.Position, Ball.Position - Vector3.new(0, 15, 0), params)
if ray and ray.Instance then
return true
else
return false
end
end
it still has the exact same effect as my first try though
Turns out you were right, I just did what you had asked wrong. I removed the minus aswell, making the raycast detect 15 studs up high. With the minus in, now my code works. Thank you!