I need my helicopter to rotate on the Y Axis/Yaw left and Right
I have got a helicopter that uses an AlignOrientation
The script currently Updates an invisible part which determines the orientation of the helicopter
I have every axis except Yaw working
Here is the function that handles flight, this runs every server heartbeat
local function Fly(Throttle,Yaw,Pitch,Roll,Occupant)
local RotationX,RotationY,RotationZ = RotationPart.CFrame:ToEulerAngles()
local Rotation
local ForceX = 0
local ForceY = 0
local ForceZ = 0
local Force = Vector3.new(ForceX, ForceY, ForceZ)
if Occupant == nil then
Rotation = CFrame.new(PrimaryPart.CFrame.Position) * CFrame.Angles(RotationX,RotationY,RotationZ)
Force = Vector3.new(0, 0, 0)
Hinge1.AngularVelocity = 0
Hinge2.AngularVelocity = 0
Exhaustsmoke.Enabled = false
VectorForce1.Enabled = false
AlignOrientation.Enabled = false
Sound1:Stop()
Sound2:Stop()
EngineSound:Stop()
else
if Throttle == 1 then
Exhaustsmoke.Enabled = true
VectorForce1.Enabled = true
AlignOrientation.Enabled = true
Hinge1.AngularVelocity = 5000
Hinge2.AngularVelocity = 50
if EngineSound.Playing == false then
EngineSound:Play()
end
if Sound1.Playing == false then
Sound1:Play()
end
if Sound2.Playing == false then
Sound2:Play()
end
if VehicleSeat.Position.Y > MaxHeight then
ForceY = (getMass(Vehicle)*game.Workspace.Gravity)
else
ForceY = (getMass(Vehicle)*game.Workspace.Gravity)+5000
end
Fuel.Value = Fuel.Value-.001
end
if Throttle == -1 then
ForceY = (getMass(Vehicle)*game.Workspace.Gravity)-4000
end
if Throttle == 0 then
ForceY = getMass(Vehicle)*game.Workspace.Gravity
end
if Pitch == 1 then
RotationZ = math.rad(-25)
end
if Pitch == -1 then
RotationZ = math.rad(25)
end
if Pitch == 0 then
RotationZ = 0
end
if Roll == 1 then
RotationX = math.rad(-25)
end
if Roll == -1 then
RotationX = math.rad(25)
end
if Roll == 0 then
RotationX = 0
end
--[[
--This is where code for the Yaw would be
if VehicleSeat.Steer == 1 then
end
if VehicleSeat.Steer == -1 then
end
]]
Rotation = CFrame.new(PrimaryPart.CFrame.Position) * CFrame.Angles(RotationX,RotationY,RotationZ):ToObjectSpace()
Force = Vector3.new(ForceX, ForceY, ForceZ)
end
RotationPart.CFrame = Rotation
VectorForce1.Force = Force
end
All the current axis tilt the helicopter to the specified angle
But the yaw needs to keep adding-subtracting so that the aircraft can turn
If anyone can help with this it would be greatly appreciated been trying to find a solution for 2 weeks
I feel like I have tried everything and I still have issues and can’t seem to implement this the way I want. I have changed over to OneAttachmentMode though that works fine. Here is what I have now:
local function Fly(Throttle,Yaw,Pitch,Roll,Occupant)
--local RotationX,RotationY,RotationZ = AlignOrientation.CFrame:ToEulerAngles()
local Rotation
local ForceX = 0
local ForceY = 0
local ForceZ = 0
local Force = Vector3.new(ForceX, ForceY, ForceZ)
if Occupant == nil then
--Rotation = CFrame.new(PrimaryPart.CFrame.Position) * CFrame.Angles(RotationX,RotationY,RotationZ)
Force = Vector3.new(0, 0, 0)
Hinge1.AngularVelocity = 0
Hinge2.AngularVelocity = 0
Exhaustsmoke.Enabled = false
VectorForce1.Enabled = false
AlignOrientation.Enabled = false
Sound1:Stop()
Sound2:Stop()
EngineSound:Stop()
else
if Throttle == 1 then
Exhaustsmoke.Enabled = true
VectorForce1.Enabled = true
AlignOrientation.Enabled = true
Hinge1.AngularVelocity = 5000
Hinge2.AngularVelocity = 50
if EngineSound.Playing == false then
EngineSound:Play()
end
if Sound1.Playing == false then
Sound1:Play()
end
if Sound2.Playing == false then
Sound2:Play()
end
if VehicleSeat.Position.Y > MaxHeight then
ForceY = (getMass(Vehicle)*game.Workspace.Gravity)
else
ForceY = (getMass(Vehicle)*game.Workspace.Gravity)+5000
end
if Fuel.Value-.1 >= 0 then
Fuel.Value = Fuel.Value-.1
end
end
if Throttle == -1 then
ForceY = (getMass(Vehicle)*game.Workspace.Gravity)-4000
end
if Throttle == 0 then
ForceY = getMass(Vehicle)*game.Workspace.Gravity
end
--Tilt Forwards/Backwards
if Pitch == 1 then
--RotationZ = math.rad(-25)
local pitchAmount = CFrame.fromAxisAngle(AlignOrientation.CFrame.LookVector, math.rad(-1))
AlignOrientation.CFrame *= pitchAmount
elseif Pitch == -1 then
--RotationZ = math.rad(25)
local pitchAmount = CFrame.fromAxisAngle(AlignOrientation.CFrame.LookVector, math.rad(1))
AlignOrientation.CFrame *= pitchAmount
elseif Pitch == 0 then
--RotationZ = 0
end
--Tilt Left/Right
if Roll == 1 then
--RotationX = math.rad(-25)
local pitchAmount = CFrame.fromAxisAngle(AlignOrientation.CFrame.RightVector, math.rad(1))
AlignOrientation.CFrame *= pitchAmount
elseif Roll == -1 then
--RotationX = math.rad(25)
local pitchAmount = CFrame.fromAxisAngle(AlignOrientation.CFrame.RightVector, math.rad(-1))
AlignOrientation.CFrame *= pitchAmount
elseif Roll == 0 then
--RotationX = 0
end
if Yaw == 1 then
local yawAmount = CFrame.fromAxisAngle(AlignOrientation.CFrame.UpVector, math.rad(-1))
AlignOrientation.CFrame *= yawAmount
elseif Yaw == -1 then
local yawAmount = CFrame.fromAxisAngle(AlignOrientation.CFrame.UpVector, math.rad(1))
AlignOrientation.CFrame *= yawAmount
end
--Rotation = CFrame.new(PrimaryPart.CFrame.Position) * CFrame.Angles(RotationX,RotationY,RotationZ):ToObjectSpace()
--AlignOrientation.CFrame = Rotation
Force = Vector3.new(ForceX, ForceY, ForceZ)
end
--RotationPart.CFrame = Rotation
VectorForce1.Force = Force
end
The thing is when I rotate one way it messes up the other angles.