Hi guys! (first devforum post btw)
-
What do you want to achieve? Keep it simple and clear!
I want to achieve a realistic flight physics system, but more specifically to this point, I wish to make it so that when the throttle is pulled up, the forward velocity moves up to that point. (Eg. engine levels of 20% will only cause a forward velocity of 20 studs/sec, and increasing throttle will cause higher forward velocity). -
What is the issue? Include screenshots / videos if possible!
The addition of delta time into my physics calculations solve a bug that I was having (drag overshooting the required drag force), but by solving this bug this new bug has came up, where the forward velocity runs away and the drag force is unable to compensate. (20% causes that 20 studs/sec forward velocity, and then this forward velocity rapidly increases continually.) -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried as much as I can, but I don’t understand why this would cause any problems. I did look for solutions, found none.
Here is my code:
local function runThrust(dt)
-- rudimentary fcs
localMovementVector += Vector3.new(0,0,-thrust * dt)
end
local function runDrag(dt)
local airDensity = 0.01
local dragTweak = 6
-- runaway drag from thrust
local dragX = (PlaneVelocity.X ^ 2) * dragPerFace.x * 0.5 * airDensity * dt * dragTweak
local dragY = (PlaneVelocity.Y ^ 2) * dragPerFace.y * 0.5 * airDensity * dt * dragTweak
local dragZ = (PlaneVelocity.Z ^ 2) * dragPerFace.z * 0.5 * airDensity * dt * dragTweak
warn(dragX,dragY,dragZ)
localMovementVector += Vector3.new(-dragX,-dragY,dragZ)
end
CONTEXT: This is run in a looping function called on Heartbeat, where the “localMovementVector” is set to Vector3.zero at the start, updated throughout the different steps, and then finally the vectorforce is set to this movement vector.
Removing the “* dt” everywhere will cause it to return back to expected functionality, with the drag overshooting problem (which is severe).
Loop code:
local function heartbeat(dt)
prevMovementVector = aircraftMainPart.VectorForce.Force
localMovementVector = Vector3.zero
-- Physics Runtime
mouseControl()
runControlSurfaces()
runLift(dt)
runDrag(dt)
runThrust(dt)
aircraftMainPart.VectorForce.Force = localMovementVector
end