# How to detect if a player is in the air or not

So, I’m making a custom movement system using vector forces, and I don’t know how to detect whether the player is in the air or not

However, this isn’t as simple as checking the Floor Material and seeing if it’s air, since I am using the physics humanoid state which doesn’t update it.

I have thought about using a raycast, whoever I have never done raycasting before and have no idea how to do it, so if possible I would like to find an easier method for doing this.

4 Likes

Not sure what you mean by “on the air,” but I’m assuming you mean whether or not a player is on the ground / in the air

Unfortunately raycasting may be one of the easier methods of doing this.
A raycast only needs two basic variables to begin using–

• an origin

and

• a direction

If your custom movement doesn’t involve a rotating character (as though it were in outer space), then your direction could easily be

``````local direction = Vector3.new(0,-10,0)
--Fill in the -10 with (  half the height of the root part + a few studs to give it room to "see"  )
``````

This direction would raycast downwards on the Y axis.
If your character rotates, you can use the root part (HumanoidRootPart if you’re using the standard character) to find which direction is currently “down.” (Not too familiar with CFrame so could use some help with this)

If raycast returns objects, then it is likely the player is not on air, if the function returns nil, then the player likely is on air.

–If you’re a dev seeing this and find errors, feel free to correct me; I’m still learning and am open to new ideas–

5 Likes

Actually Roblox has a built in property into the humanoid of a player called “FloorMaterial” when the players feet aren’t touching anything it will turn the value to “Air” as documented which will help detect if they are off the ground. Read more here: Humanoid.FloorMaterial

5 Likes

As I’ve said in my post, I am setting the humanoid’s state to Physics which makes the Floor Material property of the humanoid not update.

you can use HumanoidStateType

something like:

``````if Humanoid:GetState() == Enum.HumanoidStateType.Freefall then