|
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)
|
|
|
Bump, really need help with this. All helpful advise is appreciated.
|
|
OAuth2Join Date: 2016-11-27 Post Count: 751 |
I can't see the problem visually in my head. I'm guessing it has something to do with:
if cameraX - cameraXChase < playerX then |
|
|
^ I definitely think so. Thats probably it, idk how to fix it tho.
|
|
nixpcJoin Date: 2012-02-05 Post Count: 15425 |
"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() |
|
|
@GNUnotUNIX
Mind elaborating? Would appreciate it.
|
|
nixpcJoin Date: 2012-02-05 Post Count: 15425 |
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 |
|
OAuth2Join Date: 2016-11-27 Post Count: 751 |
^ Adding that line doesn't help..? |
|
|
Doesnt work, something else should be the problem.
|
|
|
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?
|
|
LaedereJoin Date: 2013-06-17 Post Count: 23630 |
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)
|
|
|
@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
|
|
LaedereJoin Date: 2013-06-17 Post Count: 23630 |
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)
|
|
|
@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.
|
|
|
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 |
|
|
if cameraX - cameraXChase - playerX ~= 0 then
camera.CFrame = camera.CFrame + Vector3.new(cameraSpeed, 0, 0)
end
probably smoother |
|
|
############### 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. |
|
ZyclockJoin Date: 2013-09-28 Post Count: 167 |
Huh?? |
|