Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make my custom camera follow the game character smoothly ?

I have read the tutorial about custom camera control here and got the basic understanding of it. I think the camera script in the tutorial was intended for R6 users, as it was dealing with torso of the character.

I wanted to create a basic custom camera which would be pointing to the game character and is initially placed a certain distance away from the character spawn location. After the spawn of the character, if the character move or jump in any direction my camera should also make the same move with respect to the character maintaining a certain distance.

I did little search in the internet and came up with the following code for R15 model


local camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer
local runService = game:GetService('RunService')

local pre, curr, diff

local function setupCamera()
	wait()
	pre = player.Character:WaitForChild("UpperTorso").Position
	camera.CFrame = CFrame.new(pre+Vector3.new(0, 5, 10), pre)
end

local function onUpdate()
	if pre and player.Character and player.Character:FindFirstChild("UpperTorso") then
		curr = player.Character.UpperTorso.Position
		diff = curr - pre
		pre = curr
		camera.CFrame = camera.CFrame + diff
	end
end

player.CharacterAdded:connect(setupCamera)
runService:BindToRenderStep("Camera",Enum.RenderPriority.Camera.Value,onUpdate)

The code ran as I expected it to be, but when I hit play in studio and move character the camera movement is not as smooth as the default roblox studio camera. I can see the walking type movement of my camera as it follows the character.

I tested the same code with the R6 character model by replacing UpperTorso to Torso. The R6 model gave me smooth results. R15 model has quite a little jump type camera movement. I believe it is because of the more parts involved in the character which makes the character move more realistic and in turn making my camera behave like that.

I tried to point my camera to the Head and LowerTorso but I still see the same movement.

So how can I make the camera move smoothly like the default camera does for the R15 Character model.

1 answer

✓ Accepted answer

So since R15 has lots of animated parts and R6 doesn’t, your camera would shake a lot more in R15 because the parts in R15 keeps moving and animating a lot.

I haven’t tested this since I do not have the time to check if I’m correct, but have you tried using HumanoidRootPart? I remember before when highlighting the HumanoidRootPart in studio, it does not really rotate and animate all over the place. You could use that for smoother results on R15.

Again, I don’t know if I’m correct as I don’t have time to check. I hoped this helped anyways though.

2 comments

0

Thanks a lot, after replacing "HumanoidRootPart" it works like a charm :D

0

No problem. :P

This discussion is preserved as it was. New answers, comments, and votes are closed.