Basically, I’m trying to figure out if a VehicleSeat is traveling backward or forward, without using the VehicleSeat’s Throttle property.
This is because the Throttle can be -1 even if the car is slowing down from moving forward. I want to know if it’s moving forward, even if the Throttle is -1, and vice-versa.
Is there a way to do this?
2 Likes
You could probably just use the VehicleSeat’s part properties.
Maybe something like this:
local seat = -- vehicle seat here
local function GetMoveDirection()
local direction = math.sign((seat.CFrame:Inverse() * seat.Velocity).Z)
print(direction)
return direction
end
This works, until you turn the vehicle around, and the direction flips
That’s what seat.CFrame:Inverse()
is supposed to account for, it makes sure that the Velocity from the seat is always local to the seat instead of global.
That might be, but it still flips
1 Like
I think I figured out what’s wrong, try using this function instead:
local function GetMoveDirection()
local direction = -math.sign((seat.CFrame.Rotation:Inverse() * seat.Velocity).Z)
print(direction)
return direction
end
Keep in mind that since the velocity is very sensitive, it might not ever touch 0 unless you round there. I made a different function just for that:
local function GetMoveDirection()
local direction = -(seat.CFrame.Rotation:Inverse() * seat.Velocity).Z
direction = math.abs(direction) <= 0.001 and 0 or math.sign(direction)
print(direction)
return direction
end
7 Likes
Works absolutely great, thanks!
1 Like