Aerodynamics improve

Hello, I got a aerodynamics script for my plane. When I start to fly, the plane is very shaking. How do I fix it. (If I move wings, I can handle the shake)

local Part = script.Parent
local Thrust = Instance.new("BodyThrust", Part)
Thrust.Archivable = false
math.randomseed(tick()%1*1e7)
local RayCount = 20
local RayLength = 40

while true do
	wait(1/20)
	if Part.Velocity.Magnitude > 1 then
		local XX, YX, ZX, XY, YY, ZY, XZ, YZ, ZZ = select(4, Part.CFrame:components())
		local SurfaceX = Part.Size.Y*Part.Size.Z * (XX*Part.Velocity.X + XY*Part.Velocity.Y + XZ*Part.Velocity.Z)
		local SurfaceY = Part.Size.X*Part.Size.Z * (YX*Part.Velocity.X + YY*Part.Velocity.Y + YZ*Part.Velocity.Z)
		local SurfaceZ = Part.Size.X*Part.Size.Y * (ZX*Part.Velocity.X + ZY*Part.Velocity.Y + ZZ*Part.Velocity.Z)
		local Finds = 0
		for N = 1, RayCount do
			local R = Ray.new((Part.CFrame * CFrame.new(math.random()*Part.Size.X-Part.Size.X/2, math.random()*Part.Size.Y-Part.Size.Y/2, math.random()*Part.Size.Z-Part.Size.Z/2)).p, Part.Velocity.Unit * RayLength)
			local Hit = workspace:FindPartOnRay(R, Part)
			if Hit and (Hit.Velocity - Part.Velocity).Magnitude < 1 then
				Finds = Finds + 1
			end
		end
		Thrust.Force = Vector3.new(SurfaceX, SurfaceY, SurfaceZ) * -(math.random()/3+0.66) * ((RayCount-Finds)/RayCount)
	else
		Thrust.Force = Vector3.new(0, 0, 0)
	end
end

(the code is not mine, i use it as sample)

2 Likes

Hello,

  1. You could try adjusting the multiplier (-(math.random()/3+0.66)) to see if that helps.
  2. You could also try lowering the number and length of the Raycasts and see if that helps too.

Could you please also show us a video of the plane shaking so I can see what exactly is wrong as “plane is very shaking” can mean anything.

1 Like

The shaking issue you’re experiencing with your plane might be due to the aerodynamics script applying forces randomly and abruptly, causing instability. To improve the smoothness of the flight, you can try the following modifications to the script:

  1. Smooth out the forces: Instead of applying forces randomly, you can use an average of the forces encountered during the raycasting loop. This will provide a smoother and more consistent force application.
  2. Gradually increase the force: Instead of instantly applying the force based on the velocity, you can gradually increase the force over time. This will help stabilize the plane and prevent sudden jerks.
  3. Limit the maximum force applied: To avoid excessive forces that can lead to instability, you can set a maximum force value. This will prevent extreme forces from affecting the plane’s movement.
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.