I want to detect if the player is in the air as the player’s Humanoid State Type is “Physics,” the current jump system sets the player’s state type to jump then waits 0.1 seconds and switches it back to physics, there’s one problem though. The player can jump mid air.
I’ve tried to make it detect if the player is in the air but FloorMaterial doesn’t work, I don’t know anything about raycasting, is there an easier method? Or something that has raycasting that is simple to implement?
Current Code:
--// Variables
local Player = game.Players.LocalPlayer
local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
local Root = Character:WaitForChild("HumanoidRootPart")
local uis = game:GetService("UserInputService")
local physics = false
local retracted = false
local jumpAnim = Humanoid:LoadAnimation(script.JumpAnim)
local retractAnim = Humanoid:LoadAnimation(script.RetractAnim)
Humanoid.HipHeight = -0.5
--// Event
uis.InputBegan:Connect(function(input, gameProcessedEvent)
if gameProcessedEvent then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if retracted == false then
if physics == false then
physics = true
jumpAnim:Play()
Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
else
physics = false
jumpAnim:Stop()
Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
task.wait(0.1)
Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
wait(0.5)
Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
script.ParticlesEvent:FireServer(Character, physics)
end
end
end
if input.KeyCode == Enum.KeyCode.Q then
if physics == false then
if retracted == false then
retracted = true
retractAnim:Play(0.2)
Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
else
retracted = false
retractAnim:Stop(0.2)
Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
end
end
end
end)
What happens: