I’m trying to make a script to keep a vehicle upright if it were to flip but it didn’t work and I heard about body gyro. How do I use bodygyro to flip a vehicle?
You could store the original CFrame of the part that has the gyro in it (with the vehicle being in the upright position), then when ever you need to flip it you could enable the gyro again by setting its MaxForce accordingly then setting it to the saved CFrame, then disable it (set the MaxForce back to (0, 0, 0)) as soon as it rotates back to its start position.
Sounds like it’d work, I don’t have a ton of experience working with vehicles so I’m unaware if there’s a better solution.
local runservice = game:GetService("RunService")
local CF = script.Parent.VehicleSeat.CFrame
runservice.RenderStepped:Connect(function()
if script.Parent.VehicleSeat.Orientation.X > 60 or script.Parent.VehicleSeat.Orientation.X < -60 then
script.Parent.VehicleSeat.BodyGyro.CFrame = CF
end
if script.Parent.VehicleSeat.Orientation.Z > 60 or script.Parent.VehicleSeat.Orientation.Z < -60 then
script.Parent.VehicleSeat.BodyGyro.CFrame = CF
end
end)
I tried this and it didn’t work. Could you help explain what I’m doing wrong?
What have you got the BodyGyro’s MaxTorque settings set to?
Try putting print() statements in your scripts to tell when the vehicle is over or under 60 degrees on the X axis and the same with the Z axis.
Also, you should probably be using X > math.rad(60) I believe.
I just fixed it by setting the torque and then setting the CFrame…
Did you read the last line though?
I’m pretty sure CFrame is set in radians, not degrees, so if you ask “if X > 60” you are asking the script to check if the X value is over 3437.75 degrees.
And what values do you have the MaxTorque set to?