Glitch with Helicopter Tilting and Angles

Hello,

I am having two glitches with a helicopter system of mine. The helicopter is meant to tilt right/left when it is rotating right/left, and tilt slightly forward or backward, depending on which direction is being flown. The rotating and the tilting while rotating work beautifully, but there are some other issues…

  1. One of the first issues it has is, when you start it up/first get into it, it immediately rotates to the right, instead of sticking forward to the direction it was pointed in, like seen here:


    This is relatively minor, but it is something I would like to fix. Does anyone know how?

  2. The second glitch is more detrimental to the helicopter system. Basically, when the helicopter goes forwards/backwards in its initial flight path, the tilting works fine, but when you start rotating it, the forward/backward tilt gets reversed, or starts being applied to axes that it should not be applied to. If you move back to the original axis, it recorrects itself… It’s very odd. Here is a video that shows this

Here is the relevant snippet(s) of code:

---the following are variables/lines declared/executed outside of the main loop that controls helicopter movement.
local heli = script:WaitForChild("heli",5)
local engine = heli.Value.colors.Engine
local seat = heli.Value.VehicleSeat
engine.AlignOrientation.CFrame = engine.CFrame
local angle = 0

---the below lines of code are executed inside a RenderStepped event which is effectively a loop
angle += -seat.Steer
engine.AlignOrientation.CFrame = engine.AlignOrientation.CFrame:Lerp(CFrame.fromEulerAnglesXYZ(-seat.Throttle*math.rad(5), math.rad(angle), -seat.Steer*math.rad(15)),.5)
--- above (intended) axes go as such ( forward/backward tilt, turning/rotating of heli, right/left tilt that comes with turning/rotating)

Can anyone help me with these two issues?

Your first issue probably comes from the attachment of the AlignOrientation not pointing in the same direction as the engine part. It might not be the case, but with the code you provided, that’s what I assume.
In case the AlignOrientation is initially enabled, you could fix your first issue by removing the fifth line. If the AlignOrientation is disabled, you could fix the issue by replacing the fifth line with this:

engine.AlignOrientation.CFrame = engine.AlignOrienation.Attachment0.WorldCFrame

For your second problem, it is caused because it applies the rotation in X-Y-Z order. You should use CFrame.fromEulerAnglesYXZ instead, because it applies Y rotation first.

1 Like

Your solution to the first issue did not work - it kept having the issue of turning away from where it is initially pointed.

Your solution to the second issue did work, however!