Over the shoulder camera problem

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

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

  1. 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 :slight_smile:.

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.
2 Likes

Why you don’t use mouseshiftlock?

1 Like

I want it to be smooth and not as sharp as the inbuilt shiftlock.

1 Like

The default roblox character scripts make movement pretty sharp, so if you want the camera to be smooth without modifying these scripts, it’s going to have to lag behind the player’s movements, which won’t feel very nice…

This module may do what you want

3 Likes

Still you need to lock the shift lock.

You aren’t actually calling :Play() on the tweens.
I’d highly recommend tweening the camera CFrame anyway.

Solved it.
Changed this line, from:

local targetPosition = char.HumanoidRootPart.CFrame * CameraOffset

To:

local targetCFrame = character.HumanoidRootPart.CFrame * CFrame.new(CameraOffset) * CFrame.fromEulerAnglesXYZ(0, math.rad(mouseDelta.Y), 0)

Thanks for all the replies tho.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.