Need help with AlignOrientation in my flying system

So basically I’m making a flying system and everything is working great but there is one minor problem with it that I don’t know how to fix.

For context, this system is based off of where the camera is facing so when moving forward it heads towards the camera direction. And this all works great. However, when in shift lock mode specifically, whenever I try to fly downwards the character alignment starts to go crazy and it’s really glitchy. Just an FYI, I’m using AlignOrientation for the character rotation as you will see in the code.

I have tried changing the line of code that breaks it a few times but I end up with the same result so I’m hoping someone smarter than me can figure this out lol.

Here is a video of the issue:

Here is the code that handles orientation. I put a comment where the problem is:

-- orientation
if moveVector.Magnitude > 0 then
	local cameraVector = (camera.CFrame * CFrame.new((CFrame.new(camera.CFrame.Position, camera.CFrame.Position + Vector3.new(camera.CFrame.LookVector.X, 0, camera.CFrame.LookVector.Z)):VectorToObjectSpace(character.Humanoid.MoveDirection)))).Position - camera.CFrame.Position
	moveVector = cameraVector.Unit
	vectorForce.Force += moveVector * force * primaryPart.AssemblyMass
				
	if uis.MouseBehavior ~= Enum.MouseBehavior.LockCenter then
		if math.abs(moveVector.Y) == 1 then -- look at direction and face headfirst; true condition makes sure character keeps facing the movement direction
			alignOrientation.CFrame = CFrame.lookAt(Vector3.new(0, 0, 0), moveVector, -primaryPart.CFrame.LookVector) * CFrame.fromOrientation(-math.pi / 2, 0, 0)
		else
			alignOrientation.CFrame = CFrame.lookAt(Vector3.new(0, 0, 0), moveVector) * CFrame.fromOrientation(-math.pi / 2, 0, 0)
		end
	else
		-- the problem is right here. I need to change this somehow so when in shift lock mode and facing downwards, the character alignment doesn't get all glitchy and weird
		alignOrientation.CFrame = CFrame.lookAt(Vector3.new(0, 0, 0), cameraVector --[[should i put something instead of cameraVector here?]]) * CFrame.fromOrientation(-math.pi / 2, 0, 0)
	end
else
	alignOrientation.CFrame = CFrame.lookAt(Vector3.new(0, 0, 0), camera.CFrame.LookVector) -- character stops facing headfirst when still
end

Any help is greatly appreciated.

1 Like

I had this issue before, thing is autorotate is on so

get the players character and do Character.Humanoid.AutoRotate = False

then when flying is off turn it back on

1 Like

wow I can’t believe I missed something so simple lol. Thanks!

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