AlignOrientation Strange behavior

im using align orientation for my flying system and it seems like every time i look down far enough the character will start glitching out, it looks really annoying and i don’t know how to get it to stop,

bindable.OnInvoke = function()

	if humanoid:GetAttribute("Character") == "Invincible" then

		if debounce then
			return
		end

		debounce = true

		if not isFlying then

			alignPosition = Instance.new("AlignPosition")	
			alignPosition.Mode = Enum.PositionAlignmentMode.OneAttachment
			alignPosition.MaxForce = 99999
			alignPosition.Attachment0 = humanoidRootPart.Attachment
			alignPosition.Parent = humanoidRootPart.Attachment
			
			alignOrientation = Instance.new("AlignOrientation")
			alignOrientation.Mode = Enum.OrientationAlignmentMode.OneAttachment	
			alignOrientation.Attachment0 = humanoidRootPart.RootAttachment
			alignOrientation.MaxTorque = 999999
			alignOrientation.Responsiveness = 5
			alignOrientation.Parent = humanoidRootPart.Attachment

			isFlying = true
			humanoid:SetAttribute("IsFlying", true)
		else

			alignPosition.Parent = nil

			isFlying = false
			humanoid:SetAttribute("IsFlying", false)
		end

		task.delay(4,function()
			debounce = false
		end)

	end

end

bindable2.OnInvoke = function()
	if humanoid:GetAttribute("Character") == "Invincible" then
		
		if boostDebounce then
			return
		end
		
		if humanoid.MoveDirection.Magnitude > .9 and humanoid:GetAttribute("IsFlying") then
			boostDebounce = true
			local newSound = Instance.new("Sound")
			
			newSound.SoundId = "rbxassetid://9120769331"
			newSound.Parent = humanoidRootPart
			newSound.Volume = 1.2
			newSound:Play()
			
			sonicBoomShake:ShakeOnce(25,46,.1,.3)
			humanoid:SetAttribute("FlyStrength", humanoid:GetAttribute("FlyStrength") + 50)
			task.delay(4,function()
				boostDebounce = false
			end)
		end
		
	end
end

local function handleFlying(deltaTime)

	local moveDirection = Vector3.zero
	local flyStrength = humanoid:GetAttribute("FlightStrength")
	
	if isFlying then

		if not humanoid:GetAttribute("CanFly") or humanoid:GetAttribute("Stun") > 0 then
			isFlying = false
			return
		end

		if not flyingI.IsPlaying then
			flyingI:Play(.4)
		end

		if userInputService:IsKeyDown(Enum.KeyCode.W) then

			if not flyingF.IsPlaying then
				flyingF:Play(.4)
			end

			moveDirection = camera.CFrame.LookVector
		else
			flyingF:Stop(.4)
		end

		if userInputService:IsKeyDown(Enum.KeyCode.S) then

			if not flyingB.IsPlaying then
				flyingB:Play(.4)
			end

			moveDirection -= camera.CFrame.LookVector
		else
			flyingB:Stop(.4)
		end

		if userInputService:IsKeyDown(Enum.KeyCode.A) then

			if not flyingL.IsPlaying then
				flyingL:Play(.4)
			end

			moveDirection -= camera.CFrame.RightVector
		else
			flyingL:Stop(.4)
		end

		if userInputService:IsKeyDown(Enum.KeyCode.D) then

			if not flyingR.IsPlaying then
				flyingR:Play(.4)
			end

			moveDirection += camera.CFrame.RightVector
		else
			flyingR:Stop(.4)
		end
		velocity = velocity:Lerp(moveDirection * flyStrength, traction * deltaTime)
		alignPosition.Position = humanoidRootPart.Position + velocity
		alignOrientation.CFrame = CFrame.new(camera.CFrame.Position,humanoidRootPart.Position)


I don’t know what’s causing this

1 Like

bindable.OnInvoke = function()

if humanoid:GetAttribute("Character") == "Invincible" then

    if debounce then
        return
    end

    debounce = true

    if not isFlying then
        -- Create and setup AlignPosition
        alignPosition = Instance.new("AlignPosition")
        alignPosition.Mode = Enum.PositionAlignmentMode.OneAttachment
        alignPosition.MaxForce = 99999
        alignPosition.Attachment0 = humanoidRootPart.Attachment
        alignPosition.Parent = humanoidRootPart

        -- Create and setup AlignOrientation
        alignOrientation = Instance.new("AlignOrientation")
        alignOrientation.Mode = Enum.OrientationAlignmentMode.OneAttachment
        alignOrientation.Attachment0 = humanoidRootPart.RootAttachment
        alignOrientation.MaxTorque = 1000000  -- Adjust this for smoother control
        alignOrientation.Responsiveness = 5
        alignOrientation.Parent = humanoidRootPart

        isFlying = true
        humanoid:SetAttribute("IsFlying", true)
    else
        -- Remove AlignPosition to stop flying
        alignPosition.Parent = nil

        -- Remove AlignOrientation
        alignOrientation.Parent = nil

        isFlying = false
        humanoid:SetAttribute("IsFlying", false)
    end

    -- Reset debounce after 4 seconds
    task.delay(4, function()
        debounce = false
    end)

end

end

bindable2.OnInvoke = function()
if humanoid:GetAttribute(“Character”) == “Invincible” then

    if boostDebounce then
        return
    end

    -- Handle boost when moving forward
    if humanoid.MoveDirection.Magnitude > 0.9 and humanoid:GetAttribute("IsFlying") then
        boostDebounce = true
        local newSound = Instance.new("Sound")
        
        newSound.SoundId = "rbxassetid://9120769331"
        newSound.Parent = humanoidRootPart
        newSound.Volume = 1.2
        newSound:Play()
        
        sonicBoomShake:ShakeOnce(25, 46, 0.1, 0.3)
        humanoid:SetAttribute("FlyStrength", humanoid:GetAttribute("FlyStrength") + 50)
        
        task.delay(4, function()
            boostDebounce = false
        end)
    end

end

end

local function handleFlying(deltaTime)
local moveDirection = Vector3.zero
local flyStrength = humanoid:GetAttribute(“FlyStrength”)

if isFlying then
    -- Check if the player can't fly or is stunned
    if not humanoid:GetAttribute("CanFly") or humanoid:GetAttribute("Stun") > 0 then
        isFlying = false
        return
    end

    -- Play flying animation
    if not flyingI.IsPlaying then
        flyingI:Play(.4)
    end

    -- Handle movement based on input
    if userInputService:IsKeyDown(Enum.KeyCode.W) then
        if not flyingF.IsPlaying then
            flyingF:Play(.4)
        end
        moveDirection = camera.CFrame.LookVector
    else
        flyingF:Stop(.4)
    end

    if userInputService:IsKeyDown(Enum.KeyCode.S) then
        if not flyingB.IsPlaying then
            flyingB:Play(.4)
        end
        moveDirection -= camera.CFrame.LookVector
    else
        flyingB:Stop(.4)
    end

    if userInputService:IsKeyDown(Enum.KeyCode.A) then
        if not flyingL.IsPlaying then
            flyingL:Play(.4)
        end
        moveDirection -= camera.CFrame.RightVector
    else
        flyingL:Stop(.4)
    end

    if userInputService:IsKeyDown(Enum.KeyCode.D) then
        if not flyingR.IsPlaying then
            flyingR:Play(.4)
        end
        moveDirection += camera.CFrame.RightVector
    else
        flyingR:Stop(.4)
    end

    -- Apply velocity adjustments and update position and orientation
    velocity = velocity:Lerp(moveDirection * flyStrength, traction * deltaTime)
    alignPosition.Position = humanoidRootPart.Position + velocity

    -- Ensure orientation follows camera's look direction but prevents extreme rotations
    alignOrientation.CFrame = CFrame.new(camera.CFrame.Position, humanoidRootPart.Position)

end

end

Is it when you are pointing straight down or straight up?
There’s an issue called ‘gimbal lock’ that may be affecting your flying.
If that’s the case search for it on the forums and you’ll find similar solved posts about it.

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