I am creating a 3D platformer where the main character is a bird, I am creating a script to make the player glide with its wings.
I have a problem with my script, The player clips trough the ground when holding the glide button, I cannot really find the problem but I know it must be something with raycasting, but raycasting is a nightmare to me
Anyways, here is my script
local player = game.Players.LocalPlayer
local RunService = game:GetService("RunService")
local ContextActionService = game:GetService("ContextActionService")
local char = script.Parent
falling = false
char.Humanoid.StateChanged:Connect(function(_,state)
if state == Enum.HumanoidStateType.Freefall then
falling = true
wait()
elseif state ~= Enum.HumanoidStateType.Freefall then
falling = false
wait()
end
end)
local function Glide(actionName, inputState)
if inputState == Enum.UserInputState.Begin and falling then
print("Glide active!")
script.Parent.Falldamage.TakeDamage.Value = false
local lowgrav = Instance.new("BodyVelocity")
lowgrav.Parent = char.Head
lowgrav.MaxForce = Vector3.new(0, 100000, 0)
lowgrav.P = 10000
lowgrav.Velocity = Vector3.new(0, -10, 0)
lowgrav.Name = "LowGravity"
elseif falling == false or inputState == Enum.UserInputState.End or inputState == Enum.UserInputState.Cancel or inputState == Enum.UserInputState.None then
print("Glide inactive!")
local lowgrab = char.Head:FindFirstChildOfClass("BodyVelocity")
script.Parent.Falldamage.TakeDamage.Value = true
if lowgrab then
char.Head.LowGravity:Remove()
end
end
end
game.ContextActionService:BindAction("Q", Glide, true, Enum.KeyCode.Q, Enum.KeyCode.ButtonA)
I am sorry for any spelling mistakes, I am not american and just bilengual
(P.S. I am sorry if there is a part of the script that is mildly infuriating, I am not that good of a scripter.)