I am attempting to make a plane system in which you control the operation of it with the WASD keys. W/S makes it turn up or down, and A/D makes it turn right/left.
I have constructed this simple rig to get started, before I move onto the more advanced plane models I have.
I have made the system using BodyGyro (I know it is recommended to switch to AlignOrientation but I have no had the best of luck with it, and I am far more used to BodyGyro) and LinearVelocity. The system is extremely unstable. Before, it would turn, but the turns would be horrifically overstated, and now it doesn’t do anything when I used WASD keys, as seen below.
You can see it struggles to respond to my controls.
Here is the code for it:
local seat = script.Parent.VehicleSeat
local engine = script.Parent.Part
local status = false
game["Run Service"].Heartbeat:Connect(function()
task.wait(.1)
if status == true then
if seat.Throttle == 1 then
engine.BodyGyro.CFrame = engine.BodyGyro.CFrame * CFrame.fromEulerAnglesXYZ(2, 0, 0)
elseif seat.Throttle == -1 then
--- rotate down
engine.BodyGyro.CFrame = engine.BodyGyro.CFrame * CFrame.fromEulerAnglesXYZ(-2, 0, 0)
else
engine.BodyGyro.CFrame = engine.BodyGyro.CFrame * CFrame.fromEulerAnglesXYZ(0, 0, 0)
end
if seat.Steer == 1 then
engine.BodyGyro.CFrame = engine.BodyGyro.CFrame * CFrame.fromEulerAnglesXYZ(0, 0, 2)
--- turn right
elseif seat.Steer == -1 then
engine.BodyGyro.CFrame = engine.BodyGyro.CFrame * CFrame.fromEulerAnglesXYZ(0, 0, 2)
--- turn left
else
engine.BodyGyro.CFrame = engine.BodyGyro.CFrame * CFrame.fromEulerAnglesXYZ(0, 0, 0)
end
end
if engine.LinearVelocity.MaxForce == math.huge then
engine.LinearVelocity.VectorVelocity = (engine.CFrame.lookVector)*100
end
end)
--- below is for toggling the engine on and off, not very important
engine.ClickDetector.MouseClick:Connect(function()
if seat.Occupant ~= nil then
if status == false then
status = true
engine.LinearVelocity.MaxForce = math.huge
engine.BodyGyro.MaxTorque = Vector3.new(math.huge,math.huge,math.huge)
else
status = false
engine.LinearVelocity.MaxForce = 0
engine.BodyGyro.MaxTorque = Vector3.new()
end
end
end)