Need help, camera turns 180 degrees incorrectly

Hello,

I’m trying to rotate the camera 180 degrees, it works but theres an issue…

The camera inverts when doing so, i.e. If you look up when doing a 180 turn the camera will end up looking down instead of maintaining the correct position.

Script:

userInputService.InputBegan:Connect(function(input, gameProcessed)
	if gameProcessed then return end

	if input.KeyCode == Enum.KeyCode.Z then
		local currentCFrame = currentCamera.CFrame
		local upVector = currentCFrame.UpVector
		local newLookVector = -currentCFrame.LookVector
		currentCamera.CFrame = CFrame.lookAt(currentCFrame.Position, currentCFrame.Position + newLookVector, upVector)
	end
end)

Video:

You are inverting the LookVector by doing -currentCFrame.LookVector, that inverts ALL of it’s angles. If you only want to rotate the camera 180 degrees around the Y axis, you can create a rotation matrix and multiply your camera cframe with it.

local yRotation = CFrame.Angles(0, math.rad(180), 0)

currentCamera.CFrame = currentCFrame * yRotation

Although i am not entirely sure that this is what you are looking for, could you perhaps give an example of what should happen when you press Z?

In all seriousness is the problem the fact that your controls are inverted, or the fact that your camera flips the other way?

1 Like

Here what the outcome should be (note: this was done with a custom camera thats why it works here):

bruh, nvm I was editing the mobile keybind instead of the pc one lol

I got this, in First-Person it looks alright, but in Third-Person it is pretty weird:

local currentCamera = workspace.CurrentCamera
local userInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local TSInfo = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
local TweenIsPlaying = false
userInputService.InputBegan:Connect(function(input, gameProcessed)
	if gameProcessed or TweenIsPlaying then return end

	if input.KeyCode == Enum.KeyCode.Z then
		local currentCFrame = currentCamera.CFrame
		--local upVector = currentCFrame.UpVector
		local newLookVector = -currentCFrame.LookVector
		TweenIsPlaying = true
		local Tween = TweenService:Create(currentCamera, TSInfo, {CFrame = CFrame.lookAlong(currentCFrame.Position, newLookVector)})
		Tween:Play()
		Tween.Completed:Once(function()
			TweenIsPlaying = false
		end)
	end
end)

LookAlong is basically not looking at a position, but instead looking at the same direction of a Vector.

1 Like