Using AlignOrientation for airplane dosen't work as planned

Hey creators!
I am working on a airplane system, and after searching around, I found using AlignOrientation and LinearVelocity to be the fastest way to make a good airplane system.

But when it comes to turning, everything works perfect except for when your want to do a steep turn. Like this:

What actually happens is this. It changes in the y axis, instead of doing a turn.


Here is a video demo:

External Media

This is the client script. The server clones the local script and assigns the network ownership. It’s irrelevant so I’ll just show the client where the flying happens.

-- // Services
local uis = game:GetService("UserInputService")

-- // Values
local plr = game.Players.LocalPlayer
local airplane = script.Plane.Value
local mainPart : BasePart = airplane.Main

local airplaneLV : LinearVelocity = mainPart.LinearVelocity
local airplaneAO : AlignOrientation = mainPart.AlignOrientation

local force = 0
local ori = Vector3.new(0,0,0)

-- // Requieries
local mainCamModule = require(game.ReplicatedStorage.Client.MainCameraHandler)

-- // Code

mainCamModule.unLockFP()

uis.InputBegan:Connect(function(input,chat)
	if chat then return end
	
	if input.KeyCode == Enum.KeyCode.LeftShift then
		while uis:IsKeyDown(Enum.KeyCode.LeftShift) == true do
			force += 1
			task.wait(0.1)
		end
	end
	
	if input.KeyCode == Enum.KeyCode.LeftControl then
		while uis:IsKeyDown(Enum.KeyCode.LeftControl) == true do
			force -= 1
			task.wait(0.1)
		end
	end
	
	if input.KeyCode == Enum.KeyCode.A then
		while uis:IsKeyDown(Enum.KeyCode.A) == true do
			ori += Vector3.new(0,0,1)
			task.wait(0.1)
		end
	end
	
	if input.KeyCode == Enum.KeyCode.D then
		while uis:IsKeyDown(Enum.KeyCode.D) == true do
			ori -= Vector3.new(0,0,1)
			task.wait(0.1)
		end
	end
	
	if input.KeyCode == Enum.KeyCode.W then
		while uis:IsKeyDown(Enum.KeyCode.W) == true do
			ori += Vector3.new(1,0,0)
			task.wait(0.1)
		end
	end
	
	if input.KeyCode == Enum.KeyCode.S then
		while uis:IsKeyDown(Enum.KeyCode.S) == true do
			ori -= Vector3.new(1,0,0)
			task.wait(0.1)
		end
	end
end)

while task.wait() do
	airplaneLV.VectorVelocity = mainPart.CFrame.LookVector * force
	airplaneAO.CFrame = CFrame.Angles(math.rad(ori.X),math.rad(ori.Y),math.rad(ori.Z))
end

Thanks for any help! I really appreciate it! :slight_smile:

Problem was because the orientation was changed on the worldroot and not localy.
Changeing the script to this fixed the problem:

-- // Services
local uis = game:GetService("UserInputService")

-- // Values
local plr = game.Players.LocalPlayer
local airplane = script.Plane.Value
local mainPart : BasePart = airplane.Main

local airplaneLV : LinearVelocity = mainPart.LinearVelocity
local airplaneAO : AlignOrientation = mainPart.AlignOrientation

local force = 0
local RotationCFrame = CFrame.new()

-- // Requieries
local mainCamModule = require(game.ReplicatedStorage.Client.MainCameraHandler)

-- // Code

mainCamModule.unLockFP()

uis.InputBegan:Connect(function(input,chat)
	if chat then return end
	
	if input.KeyCode == Enum.KeyCode.LeftShift then
		while uis:IsKeyDown(Enum.KeyCode.LeftShift) == true do
			force += 1
			task.wait(0.1)
		end
	end
	
	if input.KeyCode == Enum.KeyCode.LeftControl then
		while uis:IsKeyDown(Enum.KeyCode.LeftControl) == true do
			force -= 1
			task.wait(0.1)
		end
	end
	
	if input.KeyCode == Enum.KeyCode.A then
		while uis:IsKeyDown(Enum.KeyCode.A) == true do
			RotationCFrame *= CFrame.Angles(0, 0, math.rad(1))
			task.wait(0.1)
		end
	end
	
	if input.KeyCode == Enum.KeyCode.D then
		while uis:IsKeyDown(Enum.KeyCode.D) == true do
			RotationCFrame *= CFrame.Angles(0, 0, math.rad(-1))
			task.wait(0.1)
		end
	end
	
	if input.KeyCode == Enum.KeyCode.W then
		while uis:IsKeyDown(Enum.KeyCode.W) == true do
			RotationCFrame *= CFrame.Angles(math.rad(-1), 0, 0)
			task.wait(0.1)
		end
	end
	
	if input.KeyCode == Enum.KeyCode.S then
		while uis:IsKeyDown(Enum.KeyCode.S) == true do
			RotationCFrame *= CFrame.Angles(math.rad(1), 0, 0)
			task.wait(0.1)
		end
	end
end)

while task.wait() do
	airplaneLV.VectorVelocity = mainPart.CFrame.LookVector * force
	airplaneAO.CFrame = RotationCFrame
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.