Problem With Custom Camera

I’m working on a custom camera that positions itself right at the player’s eye level (using a custom character model). The game is first person. Essentially it just makes the camera bob up and down with the movement of the character to be realistic.

The camera works great so far other than 1 issue I’m having. Even when the mouse is not moving, there is a very slow movement of the camera, usually going upwards to the sky. I am unsure what is causing this even after print tests.

https://gyazo.com/daa53f842036b3cbcbeea4a0a5def51b

Code:

  local delta = uis:GetMouseDelta()
  local deltaX, deltaY = delta.X, -delta.Y
  print(deltaX..", "..deltaY)
  cam.CFrame = CFrame.new(camPos.CFrame.Position, cam.CFrame* CFrame.new(deltaX, deltaY, -500).p)
  local newRootCF = CFrame.new(root.CFrame.p,root.CFrame.p+Vector3.new(cam.CFrame.lookVector.X,0,cam.CFrame.lookVector.Z))
  root.CFrame = newRootCF

Anyone have a clue what might be causing this?

I would guess that your issue is somewhere with the bobbing code. But it would be helpful to see some of the code for this to really determine the issue.

2 Likes

Wow, forgot to post my code…

That’s a little embarrassing haha

Edited the post to include code now <3

My theory is that when I set the cframe of the torso, that causes the constant movement. The camPos variable that I use in the line where the camera’s CFrame is set is a part that is welded the character’s head at eye level by the way. So any movement of the humanoidrootpart also affects the positioning of the camPos part

1 Like

I bet the issue is GetMouseDelta. When it’s slowly drifting, is delta not zero? I think I remember having this issue before.

1 Like

delta is 0 for both axes and drifting still occurs.

@ImFarley Why don’t you try the angle/distance between the 0 delta and the delta where it slowly goes up (If it goes up, then it’s your delta + something, and the number I mean is this something), and then you just change the Y-delta, like Y-delta + something or Y-delta - something (this something is still the number you should figure out yourself, to find it you should make an equation).