|
| 28 Sep 2017 07:04 AM |
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)
|
|
|
| Report Abuse |
|
|
|
| 28 Sep 2017 07:09 AM |
Bump, really need help with this. All helpful advise is appreciated.
|
|
|
| Report Abuse |
|
|
OAuth2
|
  |
| Joined: 27 Nov 2016 |
| Total Posts: 751 |
|
|
| 28 Sep 2017 09:03 AM |
I can't see the problem visually in my head. I'm guessing it has something to do with: if cameraX - cameraXChase < playerX then |
|
|
| Report Abuse |
|
|
|
| 28 Sep 2017 09:37 AM |
^ I definitely think so. Thats probably it, idk how to fix it tho.
|
|
|
| Report Abuse |
|
|
|
| 28 Sep 2017 11:31 AM |
"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() |
|
|
| Report Abuse |
|
|
|
| 28 Sep 2017 01:03 PM |
@GNUnotUNIX
Mind elaborating? Would appreciate it.
|
|
|
| Report Abuse |
|
|
|
| 28 Sep 2017 01:05 PM |
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 |
|
|
| Report Abuse |
|
|
OAuth2
|
  |
| Joined: 27 Nov 2016 |
| Total Posts: 751 |
|
|
| 28 Sep 2017 05:50 PM |
| ^ Adding that line doesn't help..? |
|
|
| Report Abuse |
|
|
|
| 29 Sep 2017 06:32 AM |
Doesnt work, something else should be the problem.
|
|
|
| Report Abuse |
|
|
|
| 29 Sep 2017 06:35 AM |
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?
|
|
|
| Report Abuse |
|
|
Laedere
|
  |
| Joined: 17 Jun 2013 |
| Total Posts: 23601 |
|
|
| 29 Sep 2017 06:36 AM |
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)
|
|
|
| Report Abuse |
|
|
|
| 29 Sep 2017 06:39 AM |
@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
|
|
|
| Report Abuse |
|
|
Laedere
|
  |
| Joined: 17 Jun 2013 |
| Total Posts: 23601 |
|
|
| 29 Sep 2017 06:44 AM |
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)
|
|
|
| Report Abuse |
|
|
|
| 29 Sep 2017 06:56 AM |
@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.
|
|
|
| Report Abuse |
|
|
|
| 29 Sep 2017 07:23 AM |
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 |
|
|
| Report Abuse |
|
|
|
| 29 Sep 2017 07:24 AM |
if cameraX - cameraXChase - playerX ~= 0 then camera.CFrame = camera.CFrame + Vector3.new(cameraSpeed, 0, 0) end
probably smoother |
|
|
| Report Abuse |
|
|
|
| 29 Sep 2017 07:27 AM |
| ############### 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. |
|
|
| Report Abuse |
|
|
ChrisPNG
|
  |
| Joined: 28 Sep 2013 |
| Total Posts: 147 |
|
| |
|