Hello,
My group’s new game was just released. In it, we have planes, but right now there is only one plane that is used for transporting yourself and other players around the map.
It uses the old BodyMovers, which I know are depreciated, but I continued to use them since I was familiar with them + using the new constraints, was from my experience and the experience of other developers I know/work with, a PITA.
That being said, I have noticed that the BodyMovers don’t really work very well on my planes when there are multiple people in them. It can be glitchy. When there is a single person in the planes, they seem to work fine.
Anyway, I think it is time to convert my plane systems from BodyMovers to the constraint system, but I have no idea where to start… So I will describe how the planes fly + paste the code for it here.
Planes work when the player sits in the “pilot seat.” The network ownership of the “pilot seat” gets set to the player (and gets set to auto when the player leaves). Then, a local script is placed within the player, and this local script is used for controlling the plane’s movement, specifically responding to the player moving his or her mouse/cursor (or the player tapping on the screen on mobile), and orienting the plane based on that. There are no remotes involved for this. The local script has an ObjectValue in it that is used for connecting the physical plane model to the local script.
Here is the script that handles movement:
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local Humanoid = char:WaitForChild("Humanoid")
local val = script:WaitForChild("plane")
local connection = val.Value
local USINS=game:getService("UserInputService")
local engine = connection:WaitForChild("Engine")
local gyro = engine:WaitForChild("BodyGyro")
local velo = engine:WaitForChild("BodyVelocity")
local clickMove = false
function GetBankAngle(M) --This function calculates the Bank Angle
local VSX,X = M.ViewSizeX,M.X
local Ratio = (((VSX/2) - X)/(VSX/2))
Ratio = (Ratio < -1 and -1 or Ratio > 1 and 1 or Ratio)
return math.rad(Ratio * 80)
end
if connection ~= nil then
game["Run Service"].RenderStepped:Connect(function(step)
if velo.MaxForce == Vector3.new(math.huge,math.huge,math.huge) and not USINS:GetFocusedTextBox() then
Mouse.TargetFilter = game.Workspace
local BankAngle = GetBankAngle(Mouse)
--gyro.maxTorque = Vector3.new(math.huge,math.huge,math.huge)
--velo.maxForce = Vector3.new(math.huge,math.huge,math.huge)
if clickMove then
gyro.cframe = ((LastHit or Mouse.Hit)*CFrame.Angles(0,0,BankAngle))
else
gyro.cframe = (Mouse.Hit*CFrame.Angles(0,0,BankAngle))
end
velo.velocity = (engine.CFrame.lookVector)*values.currSpeed.Value
end
end)
end