So I created a script (actually 2: 1 server, 1 client) for flying a plane, nothings wrong with it I just wonder If there was a better way to make it than the method I did (body position for movement body gyro for steering)
Server
local clickDetector = script.Parent.ClickDetector
local event = script.Parent.RemoteEvent
local pilot
clickDetector.MouseClick:Connect(function(player)
if pilot == nil then
local b = Instance.new("BodyPosition")
b.Position = script.Parent.Union.Position
b.MaxForce = Vector3.new(500000000,500000000,500000000)
b.Parent = script.Parent.Union
local g = Instance.new("BodyGyro")
g.CFrame = script.Parent.Union.CFrame
g.MaxTorque = Vector3.new(500000000,500000000,500000000)
g.Parent = script.Parent.Union
local speed = 5
pilot = player
game.ReplicatedStorage.CameraEvent:FireClient(player,clickDetector.Parent.cam.CFrame,script.Parent,pilot)
local char = player.Character
char.Parent = game:GetService("ServerStorage")
char.HumanoidRootPart.Anchored = true
-- variables for ending loops
local up = false
local down = false
local left = false
local right = false
local cleft = false
local cright = false
-- movement events
event.OnServerEvent:Connect(function(player2,Type)
if player == pilot then
-- UpWard Movement
if Type == "Up" then
up = true
repeat
g.CFrame = g.CFrame:ToWorldSpace(CFrame.Angles(math.rad(5),0,0))
wait(.2)
until up == false
end
if Type == "EUp" then
up = false
end
-- DownWard Movement
if Type == "Down" then
down = true
repeat
g.CFrame = g.CFrame:ToWorldSpace(CFrame.Angles(math.rad(-5),0,0))
wait(.2)
until down == false
end
if Type == "EDown" then
down = false
end
-- LeftWard Movement
if Type == "Left" then
left = true
repeat
g.CFrame = g.CFrame:ToWorldSpace(CFrame.Angles(0,math.rad(5),0))
wait(.1)
until left == false
end
if Type == "ELeft" then
left = false
end
-- RightWard Movement
if Type == "Right" then
right = true
repeat
g.CFrame = g.CFrame:ToWorldSpace(CFrame.Angles(0,math.rad(-5),0))
wait(.1)
until right == false
end
if Type == "ERight" then
right = false
end
-- RightWard Corkswrew Movement
if Type == "CRight" then
cright = true
repeat
g.CFrame = g.CFrame:ToWorldSpace(CFrame.Angles(0,0,math.rad(-5)))
wait(.1)
until cright == false
end
if Type == "ECRight" then
cright = false
end
-- LeftWard Corkscrew Movement
if Type == "CLeft" then
cleft = true
repeat
g.CFrame = g.CFrame:ToWorldSpace(CFrame.Angles(0,0,math.rad(5)))
wait(.1)
until cleft == false
end
if Type == "ECLeft" then
cleft = false
end
if Type == "Fast" then
if speed < 30 then
speed = speed + 2
end
end
if Type == "Slow" then
speed = speed - 1
if speed == 0 then
speed = 1
end
end
if Type == "Exit" then
pilot = nil
char.HumanoidRootPart.Position = script.Parent.Union.Position
char.Parent = game.Workspace
char.HumanoidRootPart.Anchored = false
end
end
end)
-- move plane and cam
repeat
wait(.01)
b.Position = (script.Parent.Union.CFrame + script.Parent.Union.CFrame.LookVector * speed).Position
game.ReplicatedStorage.CameraEvent:FireClient(player,clickDetector.Parent.cam.CFrame,script.Parent,pilot)
until pilot == nil
b:Destroy()
g:Destroy()
end
end)
-- move client scripts parent so it can be used
script.PlaneClient.Disabled = false
script.PlaneClient.Parent = game:GetService("StarterPlayer").StarterPlayerScripts
Client
local event = game.ReplicatedStorage.CameraEvent
local plane
local pilot
local ResetCam = game.Workspace.CurrentCamera.CameraType
event.OnClientEvent:Connect(function(Cframe,plane1,pilot1)
if pilot1 ~= nil then
local cam = workspace.CurrentCamera
cam.CameraType = Enum.CameraType.Scriptable
cam.CFrame = Cframe
pilot = pilot1
plane = plane1
else
pilot = nil
end
end)
local imputService = game:GetService("UserInputService")
-- imput began
imputService.InputBegan:Connect(function(imput)
if imput.KeyCode == Enum.KeyCode.E then
if plane and pilot then
print("FiredStart")
plane.RemoteEvent:FireServer("Up")
end
end
if imput.KeyCode == Enum.KeyCode.Q then
if plane and pilot then
plane.RemoteEvent:FireServer("Down")
end
end
if imput.KeyCode == Enum.KeyCode.A then
if plane and pilot then
plane.RemoteEvent:FireServer("Left")
end
end
if imput.KeyCode == Enum.KeyCode.D then
if plane and pilot then
plane.RemoteEvent:FireServer("Right")
end
end
if imput.KeyCode == Enum.KeyCode.W then
if plane and pilot then
plane.RemoteEvent:FireServer("Fast")
end
end
if imput.KeyCode == Enum.KeyCode.S then
if plane and pilot then
plane.RemoteEvent:FireServer("Slow")
end
end
if imput.KeyCode == Enum.KeyCode.R then
if plane and pilot then
plane.RemoteEvent:FireServer("CRight")
end
end
if imput.KeyCode == Enum.KeyCode.F then
if plane and pilot then
plane.RemoteEvent:FireServer("CLeft")
end
end
if imput.KeyCode == Enum.KeyCode.X then
if plane and pilot then
for trys = 1,5 do
local cam = workspace.CurrentCamera
cam.CameraType = ResetCam
plane.RemoteEvent:FireServer("Exit")
wait(1)
end
end
end
end)
-- imput ended
imputService.InputEnded:Connect(function(imput)
if imput.KeyCode == Enum.KeyCode.E then
if plane and pilot then
plane.RemoteEvent:FireServer("EUp")
end
end
if imput.KeyCode == Enum.KeyCode.Q then
if plane and pilot then
plane.RemoteEvent:FireServer("EDown")
end
end
if imput.KeyCode == Enum.KeyCode.A then
if plane and pilot then
plane.RemoteEvent:FireServer("ELeft")
end
end
if imput.KeyCode == Enum.KeyCode.D then
if plane and pilot then
plane.RemoteEvent:FireServer("ERight")
end
end
if imput.KeyCode == Enum.KeyCode.R then
if plane and pilot then
plane.RemoteEvent:FireServer("ECRight")
end
end
if imput.KeyCode == Enum.KeyCode.F then
if plane and pilot then
plane.RemoteEvent:FireServer("ECLeft")
end
end
end)
if you want to see the plane with the scripts and stuff
library page for it