Log in to vote

How do i detect if a part is in the air?

Asked by 9 months ago

I made a car and i want to print when the car is in the air. I tried making it so when it touches a part, it prints that it touches and if it stops touching, it also prints something but that's not a good way. anybody know a better way? thanks

1 answer

Log in to vote
Answered by
oilkas 364 Moderation Voter
9 months ago

You can use raycasting, try this:

local Car = script.Parent -- Put this script in the car model.
local PrimaryPart = Car.PrimaryPart -- Set a primarypart of the car.
local Minimum = 10 -- Minimum height to register when the car is in the air.

while wait() do
    local Position = PrimaryPart.CFrame.P
    local Rotation = PrimaryPart.CFrame - Position
    local Ray =,Position -,Minimum,0)) -- Ray casted down.
    local Touch, TouchPosition = workspace:FindPartOnRay(ray, Car) -- Ignore car.
    if Touch then
        print("Touching "..Touch.Name.. " at "..TouchPosition)
        print("In air")
Thanks, this works, but what if thec ar is in another height? jdm4llfem8 94 — 9mo
wdym oilkas 364 — 9mo
with your script, if a car is on a baseplate and its on the air it works, but if the car is ontop of another part it already detects that its in the air jdm4llfem8 94 — 9mo
the part needs to be directly under the car's primarypart to detect it as on ground oilkas 364 — 9mo

Answer this question