So, in my game, there is a player who is forced first-person (via enum.CameraMode.LockFirstPerson), which works fine. I also have a function that makes the player’s body visible, as well as some animations on that body. My issue is that the player’s camera doesn’t move with their body’s head, which looks very strange in many situations.
To combat this, I added a line that set the camera’s CFrame to the head’s CFrame, but in testing this would cause the player to uncontrollably spin around.
Is there a way that I could fix the above without needing to create an entire unique camera system? Or could I use something else, like tweens?
I know that there are other posts on a similar topic, but I don’t believe the solutions were well-explained (of the ones I’ve found) and I’d like to understand the code itself before putting it into my game. So, if you could provide explanations (or point me to relevant documentation) that would be really great, but you don’t have to – anything counts. Thank you!
Setting the camera straight up directly to Head.CFrame causes two systems to conflict (roblox default camera updates the camera, then your script tries to replace it with the heads position and rotation).
You can keep the default camera and use Humanoid.CameraOffset to add ONLY the head animations movement, do not copy the heads full rotation.
I would not recommend tweens, as the target changes every animation frame. Frame rate interpolation inside of a render update is more suited I reckon.
for the camera thing, have you tried setting workspace.CurrentCamera.CameraType to Enum.CameraType.Scriptable beforehand? this disables the normal roblox camera logic
also you could just set it to enum.cameratype.follow and set the camerasubject to your body’s head or humanoidrootpart, i think that’d be better for your first person logic but its just my preference
i just tried the follow thing myself and it does not rotate your character along with your camera in first person so sorry about that
I had this issue, try using this
camera.CameraType = Enum.CameraType.Scriptable
camConnection = RunService.RenderStepped:Connect(function()
camera.CFrame = head.CFrame
end)
if it doesn’t work i dont know how to fix it then, sorry
You’re gonna encounter some weird stuff if you’re trying to set the player’s camera to follow their head.
I would first like to know if you’re trying to set the player’s head to follow the camera? If so, you’re kinda making a loop there where the head tries to follow the camera and then the camera tries to follow the head. Which would cause spinning.
I’m not gonna assume that that’s the case though. Like Jomsvikinger said, you’re kinda conflicting with Roblox’s default systems. There is a humanoid CameraOffset property you can use to offset the camera that is located within the humanoid which you can set at run time.
If neither of those is the answer to your question I wouldn’t mind a bit more clarification in what you’re trying to achieve.
Thank you to everyone who has contributed to this thread so far and sorry that it took me a few days to get back to any of you.
I think that CameraOffset is very promising (as well as being something I understand!). The only thing I can’t figure out is how to reference the head’s animation-related movements rather than its entire placement/rotation. How would I go about getting that value?
I ended up finding another thread on the topic, and found something that worked. For anyone looking at this in the future, it’s this:
local offset = (rootpart.CFrame * CFrame.new(0, 1.5, 0)):pointToObjectSpace(head.CFrame.Position)
hum.CameraOffset = offset + Vector3.new(0, 0, -0.8) -- to make sure view is not too far back
The offset makes the camera follow the head in general, but since I’m using this specifically for first person I wanted the camera to be at the front of the head, where the face is, and that’s what the the extra Vector3 ensures.