Checking if player is Grounded or not

This line of code is responsible for applying gravity to the player. there is probably a better way to achieve this so please provide feedback :slight_smile:

function Controll:GroundedOrNot()

	
	local function notInAir()
		if not self.inAir then
			player.LocalPlayer.Character.PlayerCapsul.bodyVelocity.Velocity = Vector3.new(0, 0, 0)	
			run:UnbindFromRenderStep("NotAir")
		end
	end
	
	local function notGrounded()
		if self.inAir then
			player.LocalPlayer.Character.PlayerCapsul.bodyVelocity.Velocity -= Vector3.new(0, 2, 0)	
			run:BindToRenderStep("NotAir", Enum.RenderPriority.Character.Value, notInAir)
		end
	end
	

	run:BindToRenderStep("Grounded", Enum.RenderPriority.Character.Value, notGrounded)
end


For a start use bodyforce, not sure how you detect whether player is in the air or not.

You could use humanoid.FloorMaterial

When they’re in the air, their material type will be Enum.Material.Air

3 Likes