Hello! Nathan here! Im currently experincing errors with my plane system script, where you cant go foreward nor backward, up nor down! even tho everything is correctly made! this script is currently in v1 so it has some bugs but the biggest one is that i (Again) cant go up down foreward backward and i cant seem to fix it even after lots of debugging! you can try it out, i can provide file of the roblox studio if needed
Heres the script (If local script needed i can show it)
local Event = script:WaitForChild("Control")
local RS = game:GetService("RunService")
-- constants, you know, the basics
local drag = 0.98 -- drag to slow things down a bit
local maxForwardSpeed = 100 -- max speed going forward
local maxVerticalSpeed = 50 -- max speed going up or down
local maxAngularVelocity = 100 -- how fast the plane can spin
local accelerationRate = 10 -- how quickly stuff speeds up
-- control states, like a list of what's going on with the plane
local controlState = {
Left = false, -- roll left
Right = false, -- roll right
YawLeft = false, -- yaw left (Q)
YawRight = false, -- yaw right (E)
Up = false, -- go up (W)
Down = false, -- go down (S)
ThrottleUp = false, -- throttle up (R)
ThrottleDown = false -- throttle down (F)
}
-- movement/rotation variables
local forwardVelocity = 0 -- how fast we're going forward
local verticalVelocity = 0 -- how fast we're going up/down
local angularVelocity = 0 -- how much we're spinning (roll)
local yawVelocity = 0 -- how much we're turning left or right (yaw)
local throttleMultiplier = 0 -- speed boost for going forward
-- setting up smooth rotation with BodyGyro
local plane = script.Parent
local bodyGyro = Instance.new("BodyGyro")
bodyGyro.CFrame = plane.PrimaryPart.CFrame
bodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
bodyGyro.P = 3000
bodyGyro.D = 200
bodyGyro.Parent = plane.PrimaryPart
-- setting up smooth movement with BodyVelocity
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.MaxForce = Vector3.new(50000, 50000, 50000) -- max force to move the plane
bodyVelocity.Parent = plane.PrimaryPart
-- handling control updates from the event
Event.OnServerEvent:Connect(function(player, ControlType, Do)
if ControlType and Do ~= nil then
controlState[ControlType] = Do
end
end)
-- updating plane's movement and rotation every frame
RS.Heartbeat:Connect(function(deltaTime)
-- rolling (spinning around)
if controlState.Left then
angularVelocity = math.clamp(angularVelocity + accelerationRate * deltaTime, -maxAngularVelocity, maxAngularVelocity)
elseif controlState.Right then
angularVelocity = math.clamp(angularVelocity - accelerationRate * deltaTime, -maxAngularVelocity, maxAngularVelocity)
else
angularVelocity = angularVelocity * drag
if math.abs(angularVelocity) < 0.01 then
angularVelocity = 0
end
end
-- yawing (turning left or right)
if controlState.YawLeft then
yawVelocity = math.clamp(yawVelocity + accelerationRate * deltaTime, -maxAngularVelocity, maxAngularVelocity)
elseif controlState.YawRight then
yawVelocity = math.clamp(yawVelocity - accelerationRate * deltaTime, -maxAngularVelocity, maxAngularVelocity)
else
yawVelocity = yawVelocity * drag
if math.abs(yawVelocity) < 0.01 then
yawVelocity = 0
end
end
-- vertical movement (up/down)
if controlState.Up then
verticalVelocity = math.clamp(verticalVelocity + accelerationRate * deltaTime, -maxVerticalSpeed, maxVerticalSpeed)
elseif controlState.Down then
verticalVelocity = math.clamp(verticalVelocity - accelerationRate * deltaTime, -maxVerticalSpeed, maxVerticalSpeed)
else
verticalVelocity = verticalVelocity * drag
if math.abs(verticalVelocity) < 0.1 then
verticalVelocity = 0
end
end
-- throttle (forward/backward)
if controlState.ThrottleUp then
-- speed up forward gradually
throttleMultiplier = throttleMultiplier + accelerationRate * deltaTime
forwardVelocity = math.min(forwardVelocity + throttleMultiplier * deltaTime, maxForwardSpeed)
elseif controlState.ThrottleDown then
-- slow down or go backwards
forwardVelocity = forwardVelocity - accelerationRate * deltaTime
forwardVelocity = math.max(forwardVelocity, -maxForwardSpeed) -- limit backward speed
throttleMultiplier = 0 -- no forward speed boost when going backward
else
-- drag to slow down if there's no throttle
forwardVelocity = forwardVelocity * drag
if math.abs(forwardVelocity) < 0.1 then
forwardVelocity = 0
end
end
-- apply the movement to the plane
bodyVelocity.Velocity = plane.PrimaryPart.CFrame:VectorToWorldSpace(Vector3.new(forwardVelocity, verticalVelocity, 0))
-- apply rotation to the plane
local currentCFrame = plane.PrimaryPart.CFrame
bodyGyro.CFrame = currentCFrame * CFrame.Angles(0, math.rad(yawVelocity) * deltaTime, math.rad(angularVelocity) * deltaTime)
-- debugging stuff (you can remove this later)
print("Forward Velocity:", forwardVelocity, "Vertical Velocity:", verticalVelocity)
print("Angular Velocity:", angularVelocity, "Yaw Velocity:", yawVelocity)
end)