So I asked a question a while back asking how to get the type of side view camera I need. Luckily I figured it out after a lot of troubleshooting, but now I have a new issue. Every half circle around the other player, the camera turns upside down. I believe this is due to the method I used to make sure the camera doesn't tilt when the y axes of the Torsos don't align.
I know the cause, which is the subtraction of rz from the camera's angle. I just don't have the first clue how to fix it.
Here's the script. Everything works except for the camera turning upside down.
local cam = workspace.CurrentCamera
cam.CameraType = Enum.CameraType.Scriptable
local player = game.Players.LocalPlayer
local playerOne = workspace:WaitForChild("playerOne")
local playerTwo = workspace:WaitForChild("playerTwo")
function getDistance(p1, p2)
return p1.Torso.Position - p2.Torso.Position
end
local centerPart = Instance.new("Part",workspace)
centerPart.Transparency = 1
centerPart.Anchored = true
function updateCamera(camera)
local otherPlayer
if playerTwo.Value == player.Name and playerOne.Value ~= "" then
otherPlayer = workspace:WaitForChild(playerOne.Value)
elseif playerOne.Value == player.Name and playerTwo.Value ~= "" then
otherPlayer = workspace:WaitForChild(playerTwo.Value)
end
if otherPlayer ~= nil then
local distance = getDistance(player.Character, otherPlayer)
local center = player.Character.Torso.CFrame:lerp(otherPlayer.Torso.CFrame, 1/2)
camera.CoordinateFrame = CFrame.new(center.p, otherPlayer.Torso.Position)
*CFrame.Angles(0,math.rad(90),0)
*CFrame.new(0,0,distance.magnitude/2)
local rx, ry, rz = camera.CoordinateFrame:toEulerAnglesXYZ()
print(rx.." "..ry.." "..rz)
camera.CoordinateFrame = camera.CoordinateFrame * CFrame.Angles(0,0,-rz)
else
camera.CameraType = Enum.CameraType.Track
end
end
game:GetService("RunService").RenderStepped:connect(function()
updateCamera(cam)
end)

1 comment
I'll try this out when I get a chance. I knew I wasn't doing it the most efficient way. I have a lot of trouble understanding math relating to vectors and 3D space, so I appreciate the extra-detailed explanation. Thank you!