Hi scripters. I have been working on this script for an airplane, but I decided to change the physics.
Before, I used to have the mouse position equal to the yaw, however this isnt that realistic.
I now want to achieve a point where the roll (calculated by putting mouse right/left) will be controlling the yaw. Say, I have a roll of 0.5 degrees to the right. The yaw should head to the right until it eventually completes a circle, and keep going at the same pace. If I roll to 1 degree, it should go twice as fast.
My issue is that my code quite simply isn’t working. Technically it is, but it will kinda spin off and do its own thing.
I looked for solutions, on the devforum, google, even tried asking ChatGPT, however nothing works.
My current code (snippet) looks as the following:
local pitch, z, roll = gyro.CFrame:ToEulerAnglesYXZ()
z = math.deg(z)
if math.abs(z) < 0.05 then
currentYaw = 0
z = 0
end
z = z - 0.05
local newYaw = (currentYaw + math.deg(z))
newYaw = (newYaw)
if newYaw >= 360 then
newYaw = newYaw - 360
elseif newYaw < 0 then
newYaw = newYaw + 360
end
if math.abs(newYaw - 360) < 0.1 then
newYaw = 0 -- Close to 360 degrees, wrap to 0
end
currentYaw = newYaw
print(newYaw)
local desiredRoll = math.rad(currentbank/2.5)
local pitchCFrame = CFrame.Angles(desiredPitch, 0, 0)
local rollCFrame = CFrame.Angles(0, 0, desiredRoll)
local yawCFrame = CFrame.Angles(0, math.rad(newYaw), 0)
print(yawCFrame)
targetCFrame = CFrame.new(main.Position) * yawCFrame * rollCFrame * pitchCFrame