-
What do you want to achieve? Keep it simple and clear!
I want to create a smooth camera system for my weapon system. It should be over the shoulder, similar to the Fortnite camera view. It should also rotate with the player -
What is the issue? Include screenshots / videos if possible!
**It’s not offsetting properly. The camera just goes behind the character. **
Not the best picture but you get the point.
-
What solutions have you tried so far?
I’ve tried using the inbuilt Humanoid.CameraOffset, and it works. The problem is that it isn’t smooth. So I tried using CFrame interpolation. And yes it’s smooth. But the camera is straight behind the character not up to the right.
I’m also finding it a bit hard to choose whether to use CFrame:Lerp or Tweenservice. I’m not that good with CFrames and math functions. I would appreciate any help .
Localscript (placed in StarterCharacterScripts):
local Runservice = game:GetService("RunService")
local UIS = game:GetService("UserInputService")
local plr = game.Players.LocalPlayer
local char = plr.Character
local camera = game.Workspace.CurrentCamera
local event = script.Parent.remotes.Camera
local sideView = true -- Default
local firstPersonView = false
local systemOn = false
local CameraOffset = CFrame.new(4,2,1)
local smoothing = 0.1
local function Settings()
char.Humanoid.AutoRotate = false
camera.CameraType = Enum.CameraType.Scriptable
UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
end
local function UpdateCamera()
local mouseDelta = UIS:GetMouseDelta()
local targetPosition = char.HumanoidRootPart.CFrame * CameraOffset
camera.CFrame = camera.CFrame:Lerp(targetPosition, smoothing)
end
-- Two modes: first person and side view(over the sholder)
event.OnClientEvent:Connect(function(shouldBeOn)
if shouldBeOn and not systemOn then -- Sätter på systemet
systemOn = true
Settings()
Runservice:BindToRenderStep("UpdateCamera", 1, UpdateCamera)
else
systemOn = false
char.Humanoid.AutoRotate = true
camera.CameraType = Enum.CameraType.Custom
Runservice:UnbindFromRenderStep("UpdateCamera")
end
end)
wait(25)
Runservice:BindToRenderStep("UpdateCamera", 1, UpdateCamera) -- Only used for testing.