Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
4

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

Asked by 6 years ago
Edited 6 years ago

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

Log in to vote
0
Answered by 6 years ago

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.

0
Thanks a lot, after replacing "HumanoidRootPart" it works like a charm :D diarymilk_bubly 22 — 6y
0
No problem. :P User#20279 0 — 6y
Ad

Answer this question