Plane glitches when flying upwards!

Hello, Ive come across a problem with the flight system I am trying to make, for some reason, when I fly the plane upwards it bugs out and starts jittering. Evidence:

Code:

	local GroundParams = RaycastParams.new()
	GroundParams.FilterDescendantsInstances = {Plane}
	GroundParams.FilterType = Enum.RaycastFilterType.Blacklist
	

	
	local Size = Plane.Size
	
	Mouse.TargetFilter = workspace.Fighters
	local MousePos = Mouse.hit.p                                                                                                     
	local MouseCF  = Mouse.Origin
	
	local Target = Plane.Position + ((MousePos - Plane.Position).Unit * 100)
	
	local Left = Plane.CFrame * CFrame.new(-Size.X/2, 0, 0).p
	
	local Right = Plane.CFrame * CFrame.new(Size.X/2, 0, 0).p
	
	local CheckVar = (Target - Plane.Position).Magnitude
	local FCheckVar = Plane.CFrame * CFrame.new(0, 0, -CheckVar).p
	local RotationalVar = ((FCheckVar - Target).Magnitude / 8)
	
	local LeftPoint = (Target - Left).Magnitude 
	local RightPoint = (Target - Right).Magnitude 
	
	
	local ForwardThrust = Plane.CFrame.LookVector * Speed -- + Vector3.new(0, Drag, 0)
	
	
	----Stalling-----------





	Plane.Thrust.Velocity = ForwardThrust


----------Banking
	if Plane.AssemblyLinearVelocity.Magnitude > 100 then
		
		if LeftPoint < RightPoint and LeftPoint > RotationalVar and LeftPoint < 300 then
			
			
			Plane.BodyGyro.CFrame = Mouse.Hit * CFrame.Angles(0,0,math.rad(Plane.AssemblyAngularVelocity.Y * 30))
			
			
		
		elseif LeftPoint > RightPoint and RightPoint > RotationalVar and RightPoint < 300 then
			
			
			Plane.BodyGyro.CFrame = Mouse.Hit * CFrame.Angles(0,0,math.rad(Plane.AssemblyAngularVelocity.Y * 30))
			
		else
			Plane.BodyGyro.CFrame = MouseCF				
		end
		
	end
	
	

end)```

All the help will be really appreciated!
3 Likes

Was this ever resolved? Similar issue myself.

It looks like there’s a bit of confusion regarding where the “top” direction of the plane should point when you create these CFrames.

Mouse.Origin points from the camera to the mouse.
(@OiiTaru: Mouse.Hit points in the same exact direction, except positioned at the mouse, not at the camera.)

That is a point and a direction, i.e. a ray.
However, this says nothing about the actual orientation - it’s clear where the “front” of the CFrame should point (from camera to mouse), but it’s unclear where the “top” of the CFrame should point.

Generally, CFrames made of just a direction will guess that the top should point up (as close to the Y axis).

When the plane is flying horizontally, this is a good guess.
When the plane is pointing up, the “top” direction swings wildly because it’s not clear where it should be if not up, which is where it can’t be because the front is already pointing up.

So let’s inform the CFrame’s top direction a little.

Instead of this:

local MouseCF = Mouse.Origin
-- or Mouse.Hit, as they're the same in a BodyGyro

try something like this:

local camera = workspace.CurrentCamera
local MouseCF = CFrame.lookAt(camera.Position, Mouse.Target, camera.UpVector)

This will make MouseCF point from the camera to the mouse (as before), but ensure that the ship’s top should point about the same way as the camera’s top.

This will probably cause wobbliness in some other regards, but I can’t think of any specific cases.

(edit: do note that the default Camera will generally not go upside down, so your plane will just stop turning “upward” eventually - this will probably need some tinkering on the camera script)

1 Like