Hello.
Recently I was working on a physics system for airplanes, and after a lot of research I ended up thinking that simulating physics in the airplane’s components, individually, would be more realistic.
At the moment, I haven’t made much progress in one specific part: The lift coefficient.
During some mental experiments I was doing, I couldn’t really come up with a solution to the problem I’m having now, I believe it’s more due to the burnout I had with airplane physics (and aerodynamic studies), which I redid several times until I reached a result now (which I’m doing calmly, step by step). And until then the initial result was good, since drag worked and that was a mini-progress.
If you have solutions or can help me with this, that would be more than great.
I had watched several videos, in addition to one specific video that was a unity tutorial, I translated all the cs code to luau, and I got an almost ok result, but it was extremely imprecise (because the problem was the coefficient of lift still, and the plane could never do the pitch, yaw, roll effect), but I actually did it because I couldn’t think of anything anymore.
None of the videos so far were able to help me, since the problem was in the lift coefficient, perhaps the angle of attack was the problem? I don’t know exactly what values it should return, and the idea, or concept, I already understood more than completely, but the problem was really just applying it to make something more precise, since I was thinking steps ahead to also have a stall effect for the plane.
In fact, it would be good for me to use the dot product, but I actually had more of this problem of wanting to make things realistic, and I had a certain prejudice with it. Until I can just understand the problem, and fix it, that alone would be great, maybe I could get an idea of the rest of the things to make the simulation better.
This is how the airfoil code looks like now:
function Airfoil:CalculateState(): ()
local Airfoil = self.Airfoil
local LinearVelocity = Airfoil.AssemblyLinearVelocity
local AngularVelocity = Airfoil.AssemblyAngularVelocity
if LinearVelocity.Magnitude <= 1e-4 then
LinearVelocity = Vector3.one * 1e-4
end
local LocalVelocity = Airfoil.CFrame:VectorToObjectSpace(LinearVelocity)
local LocalAngular = Airfoil.CFrame:VectorToObjectSpace(AngularVelocity)
self.LinearVelocity = LinearVelocity
self.AngularVelocity = AngularVelocity
self.LocalVelocity = LocalVelocity
self.LocalAngularVelocity = LocalAngular
end
function Airfoil:CalculateAngleOfAttack(): number
local LocalVelocity = self.LocalVelocity
return -math.atan2(LocalVelocity.Y, -LocalVelocity.Z)
end
function Airfoil:CalculateLiftCoefficient(AngleOfAttack: number): number
local CL0 = 0
local CLA = 2 * math.pi
local CL = CL0 + CLA * AngleOfAttack
if (AngleOfAttack > math.rad(15) or AngleOfAttack < math.rad(-15)) then
CL = CL * 0.5
end
return CL
end
function Airfoil:CalculateDragCoefficient(Lift: number): number
return 0.1 + (Lift^2) / (math.pi * 1.5 * 0.7)
end
--[[ Public Methods ]]--
function Airfoil:Update(DeltaTime: number): ()
self:CalculateState()
local VectorForce = self:GetForce('Physics') :: VectorForce
local Airfoil = self.Airfoil
local LocalVelocity = self.LocalVelocity
local LinearVelocity = self.LinearVelocity
local DynamicPressure = 0.5 * Utilities.AirDensity * LocalVelocity.Magnitude^2
local AngleOfAttack = self:CalculateAngleOfAttack()
local LiftCoefficient = self:CalculateLiftCoefficient(AngleOfAttack)
local DragCoefficient = self:CalculateDragCoefficient(LiftCoefficient)
local LiftDirection = Airfoil.CFrame.UpVector
local LiftForce = LiftDirection * DynamicPressure * LiftCoefficient
local DragDirection = -LinearVelocity.Unit
local DragForce = DragDirection * DynamicPressure * DragCoefficient
local TotalForce = DragForce + LiftForce
VectorForce.Force = Airfoil.CFrame:VectorToObjectSpace(TotalForce)
end
This is how it looks like now:
The goal I want to achieve: Watch goal (expecting without the problem) | Streamable
I believe I’m not too far away to achieve this, but yeah, I’m stuck at the moment.