Hey. I’m trying to create an over the shoulder camera. It currently works okay but I can’t manage to make it work exactly like I want it to. I searched for examples and solutions, here on the forum and also in other places, but didn’t find any that helped.
I am not sure what the problem is, so here are two short videos that help so you would understand what I mean:
Video of what it currently looks like (ignore the temporary model and animations)
Video of an example of what I would want it to look like
In the second video you can see that the weapon and the character are always in frame, unlike in the first video.
Here’s the code (to be honest most of it was taken from a video):
Code
local function playerInput(actionName, inputState, inputObject)
if inputState == Enum.UserInputState.Change then
rotX -= inputObject.Delta.X
rotY = math.clamp(rotY - inputObject.Delta.Y * 0.4, -75, 75)
end
end
local function updateCamera() -- Renderstepped
initialCF = CFrame.new(rootPart.CFrame.Position) * CFrame.Angles(0, math.rad(rotX), 0) * CFrame.Angles(math.rad(rotY), 0, 0)
targetPos = initialCF:PointToWorldSpace(cameraOffset)
cameraFocus = initialCF:PointToWorldSpace(Vector3.new(cameraOffset.X, cameraOffset.Y, -100000))
camera.CFrame = CFrame.lookAt(targetPos, cameraFocus)
end
ContextActionService:BindAction("PlayerInput", playerInput, false,
Enum.UserInputType.MouseMovement, Enum.UserInputType.Touch)
Like I mentioned before, I am not sure what the problem is. I am asking for the diagnosis of the problem or ideas on how to improve it (or maybe an example of the math because I’m really bad with math ). Thanks.