of     1   

ElderRaven
#225696736Thursday, September 28, 2017 12:04 PM GMT

So i'm currently learning from the roblox wiki. I have so far gathered a novice understanding of the script and how it works. I encountered a problem. When I test the script, it does work, when my character moves forward(to the right) the camera follows, but when the character moves backwards(to the left), the camera doesnt follow. My goal right now is to make the camera follow the player left and right. Here is the script, it is the same as in the wiki. local cameraHeight = 12 local cameraZOffset = 20 local cameraXChase = 20 local cameraSpeed = .25 local camera = game.Workspace.CurrentCamera local player = game.Players.LocalPlayer local RunService = game:GetService('RunService') local function setupCamera() camera.CFrame = CFrame.new(Vector3.new(0,cameraHeight,cameraZOffset), Vector3.new(0,cameraHeight,0)) end setupCamera() player.CharacterAdded:connect(setupCamera) local function onUpdate() if player.Character and player.Character:FindFirstChild('HumanoidRootPart') then local playerX = player.Character.HumanoidRootPart.Position.X local cameraX = camera.CFrame.p.X if cameraX - cameraXChase < playerX then camera.CFrame = camera.CFrame + Vector3.new(cameraSpeed, 0, 0) end end end RunService:BindToRenderStep('Camera', Enum.RenderPriority.Camera.Value, onUpdate)
ElderRaven
#225696831Thursday, September 28, 2017 12:09 PM GMT

Bump, really need help with this. All helpful advise is appreciated.
OAuth2
#225698698Thursday, September 28, 2017 2:03 PM GMT

I can't see the problem visually in my head. I'm guessing it has something to do with: if cameraX - cameraXChase < playerX then
ElderRaven
#225699322Thursday, September 28, 2017 2:37 PM GMT

^ I definitely think so. Thats probably it, idk how to fix it tho.
nixpc
#225701724Thursday, September 28, 2017 4:31 PM GMT

"local camera = game.Workspace.CurrentCamera" Because ROBLOX is pretty poopy at times, often camera will become an useless camera, if you try manipulating it, it will do nothing. Just redefine camera on every onUpdate()
ElderRaven
#225703814Thursday, September 28, 2017 6:03 PM GMT

@GNUnotUNIX Mind elaborating? Would appreciate it.
nixpc
#225703886Thursday, September 28, 2017 6:05 PM GMT

Elaboration on explaination: ROBLOX is crap Elaboration on script: local function onUpdate() camera = workspace.CurrentCamera -- this needs to be added if player.Character and player.Character:FindFirstChild('HumanoidRootPart') then local playerX = player.Character.HumanoidRootPart.Position.X local cameraX = camera.CFrame.p.X if cameraX - cameraXChase < playerX then camera.CFrame = camera.CFrame + Vector3.new(cameraSpeed, 0, 0) end end end
OAuth2
#225712817Thursday, September 28, 2017 10:50 PM GMT

^ Adding that line doesn't help..?
ElderRaven
#225730077Friday, September 29, 2017 11:32 AM GMT

Doesnt work, something else should be the problem.
ElderRaven
#225730133Friday, September 29, 2017 11:35 AM GMT

Bump, if cameraX - cameraXChase < playerX then camera.CFrame = camera.CFrame + Vector3.new(cameraSpeed, 0, 0) I have a hard time visualising this, does anyone think this is the problem?
Laedere
#225730146Friday, September 29, 2017 11:36 AM GMT

Try this: local cameraHeight = 12 local cameraZOffset = 20 local cameraXChase = 20 local cameraSpeed = .25 local camera = game.Workspace.CurrentCamera local player = game.Players.LocalPlayer local RunService = game:GetService('RunService') local function setupCamera() camera.CFrame = CFrame.new(Vector3.new(0,cameraHeight,cameraZOffset), Vector3.new(0,cameraHeight,0)) end setupCamera() player.CharacterAdded:connect(setupCamera) local function onUpdate() if player.Character and player.Character:FindFirstChild('HumanoidRootPart') then local playerX = player.Character.HumanoidRootPart.Position.X local cameraX = camera.CFrame.p.X camera.CFrame = camera.CFrame + Vector3.new(cameraSpeed, 0, 0) end end RunService:BindToRenderStep('Camera', Enum.RenderPriority.Camera.Value, onUpdate)
ElderRaven
#225730183Friday, September 29, 2017 11:39 AM GMT

@Laedere I just tried that, the camera kept moving left regardless if I moved my character or not. This problem seems pretty difficult. Thanks tho
Laedere
#225730262Friday, September 29, 2017 11:44 AM GMT

Then try this, it will probably work. local cameraHeight = 12 local cameraZOffset = 20 local cameraXChase = 20 local cameraSpeed = .25 local camera = game.Workspace.CurrentCamera local player = game.Players.LocalPlayer local RunService = game:GetService('RunService') local function setupCamera() camera.CFrame = CFrame.new(Vector3.new(0,cameraHeight,cameraZOffset), Vector3.new(0,cameraHeight,0)) end setupCamera() player.CharacterAdded:connect(setupCamera) local function onUpdate() if player.Character and player.Character:FindFirstChild('HumanoidRootPart') then local playerX = player.Character.HumanoidRootPart.Position.X local cameraX = camera.CFrame.p.X if cameraX - cameraXChase < playerX then camera.CFrame = camera.CFrame + Vector3.new(cameraSpeed, 0, 0) else camera.CFrame = camera.CFrame - Vector3.new(cameraSpeed, 0, 0) end end end RunService:BindToRenderStep('Camera', Enum.RenderPriority.Camera.Value, onUpdate)
ElderRaven
#225730455Friday, September 29, 2017 11:56 AM GMT

@Laedere Great! That actually worked, altho... now theres another problem. When my character is not moving, theres a sort of shaky vibration in the camera.
TheFishToucher
#225730885Friday, September 29, 2017 12:23 PM GMT

if cameraX - cameraXChase < playerX then camera.CFrame = camera.CFrame + Vector3.new(cameraSpeed, 0, 0) elseif cameraX - cameraXChase > playerX then camera.CFrame = camera.CFrame - Vector3.new(cameraSpeed, 0, 0) end
TheFishToucher
#225730907Friday, September 29, 2017 12:24 PM GMT

if cameraX - cameraXChase - playerX ~= 0 then camera.CFrame = camera.CFrame + Vector3.new(cameraSpeed, 0, 0) end probably smoother
ElderRaven
#225730972Friday, September 29, 2017 12:27 PM GMT

############### While Laedere's script fixed the problem, i'll be making another thread based on this new problem. Both the scripts didnt work, the second one made the camera move without my player moving. Appreciate it tho.
Zyclock
#225803903Sunday, October 01, 2017 1:51 AM GMT

Huh??

    of     1