I am trying to make a car-flip script, and for that i need to determine if it is upside down.
I’m thinking of doing something like:
if car.Orientation.X < 90 or car.Orientation.X > -90 or car.Orientation.Z < 90 or car.Orientation.Z > -90 then
--flip
end
But surely there must be a better way to do this rather than running checks
3 Likes
That’s probably exactly how I would do it
3 Likes
Fair enough, thanks for the reply
2 Likes
You can cast a unit ray down and check if the position is smaller than the actual position:
if Car.Position.Y + Vector3.new(0, Car.CFrame.UpVector.Unit) < Car.Position.Y then
-- do something
end
3 Likes
Kacper
(Kacper)
May 18, 2020, 8:55pm
5
We will need two vectors:
Let’s create a third vector p2 = position + UpVector
Compare the Y coordinates of position and p2. If p2.Y is < position.Y then the part is upside down.
function isUpsideDown(part)
local UpVector = part.CFrame.UpVector
local position = part.Position
return position.Y > (position + UpVector).Y
end
Simple vector addition makes this very efficient.
13 Likes
Life_Blox
(Life_Blox)
February 7, 2025, 4:05pm
6
Sorry to bump this old thread, but I noticed that the solution provided got the position involved needlessly.
(A > A + B) rather than (0 > B).
Here’s a simplified approach that doesn’t require the part Position to be used.
(it simply checks if the UpVector is negative)
function isUpsideDown(part)
local UpVector = part.CFrame.UpVector
return UpVector.Y < 0
end
4 Likes