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 though 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.
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–
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