Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does my object rotate in an axis it's not supposed to?

Asked by 4 years ago

I’m doing right now a hovering-car system using bodymovers. For rotations, I’m using BodyGyros, and changing its CFrame property when the player steers the vehicle. What I want to do is kind of a leaning effect, where the hovercar leans to the left/right like a spaceship (in the Z-axis) at the same time it rotates (in the Y-axis). The thing is, whenever I change the rotation in the 2 axes of the bodygyro, it also moves in the third (The X, which is the one I don’t want to rotate to). I am aware this is a “natural effect” of math itself, but I really don’t know how to solve it. Here’s the code that steers the vehicle:

I’ve tried to use CFrame.Angles() and CFrame.fromOrientation()

if seat.Steer == -1 then
        gyro.CFrame = CFrame.fromOrientation(math.rad(mainpart.Orientation.X), math.rad(mainpart.Orientation.Y + rotationAmmount), math.rad(25))
        --gyro.CFrame = CFrame.fromOrientation(math.rad(mainpart.Orientation.X), math.rad(mainpart.Orientation.Y), math.rad(25))
    elseif seat.Steer == 1 then
        gyro.CFrame = CFrame.fromOrientation(math.rad(mainpart.Orientation.X), math.rad(mainpart.Orientation.Y - rotationAmmount), math.rad(-25))
        --gyro.CFrame = CFrame.fromOrientation(math.rad(mainpart.Orientation.X), math.rad(mainpart.Orientation.Y), math.rad(-25))
    else
        gyro.CFrame = CFrame.fromOrientation(math.rad(mainpart.Orientation.X), math.rad(mainpart.Orientation.Y), math.rad(0))
end

https://i.gyazo.com/149bbc79f208f22b4b230453a82e2c39.gif

Answer this question