I have an isometric camera system for my game and ive made a script that follows the mouse a small bit to make it feel better. Like this.
now as you can see this works great when moving the mouse up and down. The problem however arises when you move the mouse left and right. For example.
As you can see, the camera is being a very bad boy by skewing abit down when i move the mouse to the right and skewing up when i move the mouse to the left. Santa will clearly not be at all delighted by this and will probably gift him coal this christmas.
With that being said, whats the best way to discipline my naughty camera system? Thank you.
here code btw
runService.RenderStepped:Connect(function()
if character then
if character:FindFirstChild("Head") then
local mousePos = Vector2.new(mouse.X, mouse.Y)-(camera.ViewportSize*0.5)
game:GetService("SoundService"):SetListener(Enum.ListenerType.ObjectCFrame, character.Head)
local pos = Vector3.new(character.Head.Position.X + mousePos.X/100 + ((mousePos.Y/100)), character.Head.Position.Y, character.Head.Position.Z + ((mousePos.Y/100)))
camera.CFrame = CFrame.new(Vector3.new(pos.X + zoom, pos.Y + zoom, pos.Z + zoom), pos)
end
end
end)
1 Like
Wouldn’t it be much easier to use CameraOffset in the player’s humanoid instead?
oh my god why didnt i think of that
Nevermind it doest work. How would i implement that? like this??
runService.RenderStepped:Connect(function()
if character then
if character:FindFirstChild("Head") then
local mousePos = Vector2.new(mouse.X, mouse.Y)-(camera.ViewportSize*0.5)
game:GetService("SoundService"):SetListener(Enum.ListenerType.ObjectCFrame, character.Head)
local pos = Vector3.new(character.Head.Position.X + mousePos.X/100 + ((mousePos.Y/100)), character.Head.Position.Y, character.Head.Position.Z + ((mousePos.Y/100)))
humanoid.CameraOffset = Vector3.new(mousePos.X, 0, mousePos.Y)
camera.CFrame = CFrame.new(Vector3.new(pos.X + zoom, pos.Y + zoom, pos.Z + zoom), pos)
end
end
end)
Not quite, if you edit the CameraOffset, you don’t need to edit the CFrame of the camera as well.
runService.RenderStepped:Connect(function()
if character then
if character:FindFirstChild("Head") then
local mX,mY = mouse.ViewSizeX/2,mouse.ViewSizeY/2
local mousePos = Vector2.new(mouse.X, mouse.Y)-Vector2.new(mX,mY)
humanoid.CameraOffset = Vector3.new(mousePos.X/mX, 0, mousePos.Y/mY)
end
end
end)
I am not sure if it will work when the character gets twisted around though…