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)
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.
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.