Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you rotate the camera around the player properly?

Asked by
Nezuo 0
5 years ago

https://gyazo.com/a476eca92dae1f9d41602b9069125f82

I want the camera to rotate around the character, but it rotates around itself...

You can see the unwanted behavior in the GIF above.

UserInputService.InputChanged:Connect(function(input)
    if (input.UserInputType == Enum.UserInputType.MouseMovement) then
        xAngle = xAngle - input.Delta.X
        yAngle = math.clamp(yAngle - input.Delta.Y, -80, 80)
    end
end)

RunService.RenderStepped:Connect(function(dt)
    local CameraX = CurrentCamera.CFrame.X + (HumanoidRootPart.Position.X + OFFSET.X - CurrentCamera.CFrame.X)*0.1*(1+dt)
    local CameraY = CurrentCamera.CFrame.Y + (HumanoidRootPart.Position.Y + OFFSET.Y - CurrentCamera.CFrame.Y)*0.2*(1+dt)
    local CameraZ = CurrentCamera.CFrame.Z + (HumanoidRootPart.Position.Z + OFFSET.Z - CurrentCamera.CFrame.Z)*0.2*(1+dt)

    local CameraCFrame = CFrame.new(CameraX, CameraY, CameraZ)*CFrame.Angles(0,rad(xAngle),0)*CFrame.Angles(rad(yAngle),0,0)
    local TargetCFrame = CameraCFrame + CameraCFrame:VectorToWorldSpace(Vector3.new(OFFSET.X, OFFSET.Y, -50000))

    CurrentCamera.CFrame = CFrame.new(CameraCFrame.Position, TargetCFrame.Position)
end)
0
there is a circling part script on the wiki: https://developer.roblox.com/articles/Camera-manipulation INOOBE_YT 387 — 5y

Answer this question