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