In this project I am using the older body movers like BodyVelocity and BodyGyro; I know they are depreciated, but I have experimented with the constraint replacements for them, and I did not find them to be as flexible or easy to use as the older BodyMovers are. I would greatly appreciate any answers to this question using the new constraint replacements for them in their answer to help me get the hang of them, but it isn’t necessary at this time.
I’m working on a helicopter system that relies on a VehicleSeat’s throttle and steer components to control left/right and forward/backward movement, so that it will be more cross-platform friendly. In addition, I have it so that the helicopter’s orientation is determined by the player’s mouse moving constantly (I will change this for mobile players obviously), and the player will use Left Shift/Left Control to go up/down (again, as this system progresses further along, I will add more cross-platform friendly controls).
So far I have gotten the basic’s down, but I am running into some issues:
I cannot have multiple controls going at once. For example, if I try to combine going up in the helicopter with going forward, going forward with override the going up control and I will stop going up when I start going forward. Here is a gif of the problem.
Controls don’t stop until another control overrides them. If I go forward, the only way to stop would be to choose another control, like going backwards, up or down, or left and right. I know a fix to this but I fear that it will make the issue in #1 even worse. Here is a gif of the problem.
I apologize if those gifs don’t help visualize the issues very well.
The following is the server-sided code used for the mode:
local seat = script.Parent.VehicleSeat local engine = script.Parent.Engine local gyro = engine.BodyGyro local speed = engine.BodyVelocity local maxSpeed = 100 local minSpeed = 0 local connection = script.Parent.Control local inc = 10 local height = 0 --- 0 for no height change, -1 for down, 1 for up. local Mouse = Vector3.new(0,0,0) seat:GetPropertyChangedSignal("Occupant"):connect(function() local Humanoid = seat.Occupant local Char = Humanoid and Humanoid.Parent local Player = Char and game.Players:GetPlayerFromCharacter(Char) local controlla = script.LocalScript:Clone() controlla.heli.Value = script.Parent if Player then controlla.Parent = Char controlla.Disabled = false speed.MaxForce = Vector3.new(math.huge,math.huge,math.huge) gyro.maxTorque=Vector3.new(1e4,1e4,1e4) repeat if height == 1 then -- we going up speed.Velocity = (engine.CFrame.UpVector)*inc end if height == -1 then -- we going down speed.Velocity = (engine.CFrame.UpVector)*-inc end if seat.Throttle == 1 then --- we are going forward speed.Velocity = (engine.CFrame.lookVector)*inc end if seat.Throttle == -1 then --- we are going backwards speed.Velocity = (engine.CFrame.lookVector)*-inc end if seat.Steer == 1 then --- we are going right speed.Velocity = (engine.CFrame.RightVector)*inc end if seat.Steer == -1 then --- we are going left speed.Velocity = (engine.CFrame.RightVector)*-inc end game["Run Service"].Heartbeat:wait(1) until not seat.Occupant end end) connection.OnServerInvoke = (function(player,mouse,heightChange) if mouse ~= nil then -- constantly updating the orientation of the model to the player's mouse. Mouse = mouse gyro.cframe = mouse end height = heightChange --- constantly checking for changes in height. end)
Client-sided code for controlling:
local player = game.Players.LocalPlayer local mouse = player:GetMouse() local inputS=game:getService("UserInputService") mouse.Move:connect(function() --if inputS.TouchEnabled == false then if script.heli.Value ~= nil then script.heli.Value.Control:InvokeServer(mouse.Hit) end end) inputS.InputBegan:connect(function(input) local code=input.KeyCode if code==Enum.KeyCode.LeftShift or code==Enum.KeyCode.DPadUp then script.heli.Value.Control:InvokeServer(mouse.Hit,1) elseif code==Enum.KeyCode.LeftControl or code == Enum.KeyCode.DPadDown then script.heli.Value.Control:InvokeServer(mouse.Hit,-1) end end) inputS.InputEnded:connect(function(input) local code=input.KeyCode if (code==Enum.KeyCode.LeftShift or code == Enum.KeyCode.DPadUp) or (code==Enum.KeyCode.LeftControl or code == Enum.KeyCode.DPadDown) then script.heli.Value.Control:InvokeServer(mouse.Hit,0) end end)