The code doesn't work very good :( Can someone help me how to make that focussing of the cam smoother?
local cam = game.Workspace.CurrentCamera local plr = game.Players.LocalPlayer local mouse = plr:GetMouse() local focus = Instance.new("Part", game.Workspace) focus.Anchored = true focus.CanCollide = false focus.Transparency = 1 local bp = Instance.new("BodyPosition", focus) bp.D = 1250 bp.P = 10000 bp.position = focus.Position bp.maxForce = Vector3.new(0, 0, 1000000) while wait() do focus.Position = plr.Character.Torso.Position bp.position = focus.Position cam.CameraSubject = focus cam.CameraType = Enum.CameraType.Attach cam.CoordinateFrame = CFrame.new(0,10, 10) end
We can make the maxForce infinity using math.huge
.
local infinity = math.huge
In order to get RenderStepped we need to get to the RunService.
game:GetService("RunService") --Done.
Now we need to get RenderStepped, which is an event.
game:GetService("RunService").RenderStepped --This only works in LOCAL SCRIPTS
Now we just add a connection and a function and an end.
game:GetService("RunService").RenderStepped:connect(function() print("Foo") end)
RunService is 2x faster than wait().
here is your script if you followed everything I told you to do.
local cam = game.Workspace.CurrentCamera local plr = game.Players.LocalPlayer local mouse = plr:GetMouse() local focus = Instance.new("Part", game.Workspace) focus.Anchored = true focus.CanCollide = false focus.Transparency = 1 local bp = Instance.new("BodyPosition", focus) bp.D = 1250 bp.P = 10000 bp.position = focus.Position bp.maxForce = Vector3.new(math.huge,math.huge,math.huge) game:GetService("RunService").RenderStepped:connect(function() focus.Position = plr.Character.Torso.Position bp.position = focus.Position cam.CameraSubject = focus cam.CameraType = Enum.CameraType.Attach cam.CoordinateFrame = CFrame.new(0,10, 10) end)
Also, instead of making the camera's target the focus, we can use interpolate instead. Interpolate can make your camera slide smoothly. This way, we don't rely on parts and stuff.
Example of Interpolate:
--LocalScript workspace.Camera:Interpolate(50,10,15, game:GetService("Players").LocalPlayer.Character.HumanoidRootPart, 5) --50,10,15 is the Position where the camera will go, the HumanoidRootPart is the focus. 5 is how many seconds it will take to get to the position. The position could also be the character's Torso!
Hope this helps!
If you change the wait()
in your while do
function to game:GetService('RunService').RenderStepped:wait()
then it should run a lot smoother!