LinearVelocity Flight System Extreme Glitch

Hi, I have a flight system and currently it works really good apart from a big problem that keeps randomly occurring. The problem is that suddenly the character bugs out and the graphics level is automatically set to 1.


I have no idea where it is coming from and cant fix it which is really annoying.

This is basically what my code for the flying physics is: (local script in StarterCharacterScripts)

local function Fly()

	UpMaid = Maid.new()
	FlightControlMaid = Maid.new()

	flightForce = Instance.new("LinearVelocity")
	flightAlign = Instance.new("AlignOrientation")

	FlightControlMaid:GiveTask(flightForce)
	FlightControlMaid:GiveTask(flightAlign)

	flightForce.Enabled = true
	flightAlign.Enabled = true

	flightForce.MaxForce = 100000
	flightForce.Attachment0 = Player.Character.HumanoidRootPart.RootAttachment	

	flightAlign.MaxTorque = math.huge
	flightAlign.MaxAngularVelocity = math.huge
	flightAlign.Responsiveness = 20

	flightAlign.RigidityEnabled = false

	flightAlign.Parent = On and Player.Character.HumanoidRootPart or nil
	flightForce.Parent = On and Player.Character.HumanoidRootPart or nil

	flightAlign.Attachment0 = Player.Character.HumanoidRootPart.RootAttachment	
	flightAlign.Mode = Enum.OrientationAlignmentMode.OneAttachment
	flightAlign.CFrame = Player.Character.HumanoidRootPart.CFrame	

	Player.Character.Animate.Disabled = true

	MomentumDirection = nil

	if PowerStatusClient.GetPowerStatus("Flight") == true then

		FlightControlMaid.FlightSteppeed = RunService.RenderStepped:Connect(function(Delta)		

			Player.Character.Animate.Disabled = true

			local MoveVector = controlModule:GetMoveVector()
			local Direction = Camera.CFrame.RightVector * (MoveVector.X) + Camera.CFrame.LookVector * (MoveVector.Z * -2)

			if Direction:Dot(Direction) > 0 then
				Direction = Direction.Unit
			end 

			if MomentumDirection == nil then

				MomentumDirection = Direction

			end	

			flightForce.VectorVelocity = MomentumDirection * SpeedValue.Value

			if Player.Character.Humanoid.MoveDirection.Magnitude <= 0 then -- If Player Is Not Moving			

				Player.Character.Humanoid.AutoRotate = false	

				flightAlign.CFrame = Camera.CFrame


			elseif Player.Character.Humanoid.MoveDirection.Magnitude > 0 then -- If Player Is Moving			

				if MomentumDirection ~= Direction then					
					MomentumDirection = Direction					
				end					

				Player.Character.Humanoid.AutoRotate = false

				local MoveDirection = Player.Character.HumanoidRootPart.CFrame:VectorToObjectSpace(Direction)

				local Tilt = (CFrame.lookAt(Player.Character.HumanoidRootPart.CFrame.Position, Player.Character.HumanoidRootPart.CFrame.Position + Direction))
					* CFrame.Angles(0, 0, -math.asin(MoveDirection.X) * 1.5)
					* CFrame.fromOrientation(-math.pi / 2, 0, 0)

				flightAlign.CFrame = Tilt

			end	

		end)

	end

end

EDIT: The solution in this post unfortunately stopped working a couple months afterwards and I cant really do anything since the post is locked (very sorry drew). I found out a new possible was to solve it would be to check if the velocity would be set to NAN and then changing it to a blank vector3.

if MovePosition.Unit ~= MovePosition.Unit then MovePosition = Vector3.new(0 ,0, 0) end flightForce.VectorVelocity = MovePosition

3 Likes

Probably math.huge is a issue there try to set it to 999

2 Likes

Thank you for your help! But after testing this it still has the same issue :frowning:

I have found that once you disable both the AlignOrientation and LinearVelocity at the same time then it stops glitching out but if you only have one enabled then it continues glitching.

It happend when you turn on/off flight mode?

When on flight mode it will just start glitching at a completely random moment, I think that the problem is coming from the LinearVelocity and the AlignOrientation properties.

Try using this, if its still not working then you can try use BodyVelocity and BodyGyro

Its still not working sadly but thank you for trying to help :slight_smile:

I was having similar issues yesterday with a character controller thing I’m making.

Basically what’s (most likely) happening is that the character’s position is being set to NaN which causes the character to flash and the graphics quality is degraded because your character is so far away. (Due to graphics LOD)

One strange fix I found was to make sure no components/numbers in the CFrame had too many digits past the decimal point.

Basically the strange issue I had cause it:
1.826262826252672 = not good
1.8262 = good

I’m not sure if this will fix your issue but try using this on the AlignOrientation’s target CFrame:

local Components = table.pack(TargetCFrame:GetComponents())

for i, num in Components do
Components[i] = math.floor(num * 1000)/1000
end

local NewCFrame = CFrame.new(table.unpack(Components))

Use the NewCFrame on the AlignOrientation.
You could do something similar with the LinearVelocity if that’s also causing issues too but test with only the AlignOrientation enabled using the code above.

Sorry if the formatting is weird or something I’m writing this on mobile.
Also I’m not sure if this will work for you but it worked for me, if this doesn’t work I can try to help a bit more tomorrow if it’s not solved by then.

1 Like

When this happend it turn off fly mode?

Wow I think it is actually working thank you I’ve been testing it for about 5 minutes and it isn’t glitching out of control at all! (It was glitching when only applied to the AlignOrientation but I added it to the LinearVelocity as well and its fine!) But since it happens really randomly and unexpected if it hasn’t glitched out at all by tommorow then I’ll mark it as the solution.

1 Like

Yeah when I turn off flight mode and turn it back on it deletes the current AlignOrientation and LinearVelocity and makes new ones which fixes it.

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