hello
so i’m making a flight mode for the player character but when i fly down or you could say towards the ground hoping his feet don’t pierce the ground and the flight mode turns off, i’ve tried turning it off when it touches a horizontal object only if his feet touch a vertical object like a wall the flight mode won’t turn off, all suggestions are welcome
heres the function i made to detect the ground with player legs :
-- Function to check if the player is touching the ground while airwalking
function checkGroundTouch()
local leftLeg = character:FindFirstChild("Left Leg")
local rightLeg = character:FindFirstChild("Right Leg")
if not leftLeg or not rightLeg then
return
end
-- Function to handle the ground touch logic using legs
local function handleGroundTouch(hit)
if airwalking and hit.CanCollide then
-- Get the normal of the surface
local normal = hit.CFrame:VectorToWorldSpace(Vector3.new(0, 1, 0))
-- Calculate the vertical threshold
local verticalThreshold = 0.7 -- Adjust this threshold as needed
-- Check if the hit surface is mostly vertical or horizontal
if normal.Y < verticalThreshold then
-- It's a horizontal surface
local isGround = (hit:IsA("Part") and (hit.Material == Enum.Material.Grass or hit.Material == Enum.Material.SmoothPlastic))
if isGround then
print("Ending airwalk: Touched Ground.")
airwalkEnd()
end
else
print("Touched vertical surface: Continuing airwalk.")
end
end
end
-- Function to continuously check for ground contact while flying
local function checkGroundBelow()
while airwalking do
wait(0.1)
local rayOrigin = leftLeg.Position
local rayDirection = Vector3.new(0, -1, 0) * 10 -- Length of the raycast
local ray = Ray.new(rayOrigin, rayDirection)
local hit, position = workspace:FindPartOnRay(ray, character)
if hit and hit.CanCollide then
local isGround = (hit:IsA("Part") and (hit.Material == Enum.Material.Grass or hit.Material == Enum.Material.SmoothPlastic))
if isGround then
print("Ending airwalk: Touched Ground from raycast.")
airwalkEnd()
break
end
end
end
end
leftLeg.Touched:Connect(handleGroundTouch)
rightLeg.Touched:Connect(handleGroundTouch)
checkGroundBelow()
end
Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
checkGroundTouch(character)
end)
end)
for _, player in pairs(Players:GetPlayers()) do
if player.Character then
checkGroundTouch(player.Character)
end
end
here the problem ive been facing
robloxapp-20241023-0453540.wmv (2.8 MB)