Essentially, I plan to have the player’s camera unlock from the Custom state (which I’ve done), and then have it slowly pan over to an object in the air. I imagine I’d use renderstepped for a smooth transition, but I wasn’t sure how the orientation of the camera would be changed since that involves a lot of math typically. Help would be appreciated.
No it doesn’t need much math to be honest, you can just use PreRender (RenderStepped is deprecated) and CFrame.lookAt().
local RunService = game:GetService("RunService")
local camera = workspace.CurrentCamera -- Gets the current camera, local script only.
local objectToFocus = Path.To.Object
camera.CameraType = Enum.CameraType.Scriptable -- Set the CameraType to scriptable so the core scripts don't override it.
RunService.PreRender:Connect(function() -- Runs every time before rendering (before client sees anything visually).
camera.CFrame = CFrame.lookAt(camera.CFrame.Position, objectToFocus.CFrame.Position)
end)
(I’ve edited the whole post because I’ve understood it completely wrong.)
that does set the target for the camera, but like in my post I was looking for something that would ‘pan’ over. Like rather than being an instant change it would just move the player’s camera over slowly to look at said object. This is why I wasn’t sure what to do.
Then use TweenService instead of RunService:
local TweenService = game:GetService("TweenService")
local camera = workspace.CurrentCamera -- Gets the current camera, local script only.
local objectToFocus = Path.To.Object
camera.CameraType = Enum.CameraType.Scriptable -- Set the CameraType to scriptable so the core scripts don't override it.
local tweenInfo = TweenInfo.new(1) -- Customize it however you want.
TweenService:Create(camera, tweenInfo, {CFrame = CFrame.lookAt(camera.CFrame.Position, objectToFocus.CFrame.Position)}):Play()
This will make the camera tween to to the object only once, if you want you can use loops or RunService again combined with TweenService so it continues to follow the part smoothly(with easing) as it moves.
Thanks a bunch, with some configuring I got it working pretty much how I was trying to get it to work.
one small issue I’ve realized is that because I’m running the tween in PreRender I have no idea how to stop it with the layout I have for my script. I’ve tried using task.spawn and task.cancel to stop the function but that doesn’t work for this.
local cinemamodule = require(game.StarterPlayer.StarterCharacterScripts.cinemaModule)
local Controls = require(game.Players.LocalPlayer.PlayerScripts.PlayerModule):GetControls()
local function ballEvent1Client()
local runServce = game:GetService("RunService")
local tweenService = game:GetService("TweenService")
local plr = game.Players.LocalPlayer
local part = game.Workspace:WaitForChild("ball")
local sound = Instance.new("Sound", game.SoundService)
sound.SoundId = "rbxassetid://836142578"
sound.Volume = 2
local cam = game.Workspace.CurrentCamera
task.wait(3)
cinemamodule.cinematicBars()
Controls:Disable()
cam.CameraType = Enum.CameraType.Scriptable
sound:Play()
local tweenInfoCam = TweenInfo.new(1.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
local tweenInfoCam2 = TweenInfo.new(3, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut)
local tweenInfoCam3 = TweenInfo.new(1, Enum.EasingStyle.Sine)
local tweenCam = tweenService:Create(cam, tweenInfoCam, {FieldOfView = 90}) -- default is 70
tweenCam:Play()
local preTween = tweenService:Create(cam, tweenInfoCam2, {CFrame = CFrame.lookAt(cam.CFrame.Position, part.CFrame.Position)})
task.wait(2)
preTween:Play()
preTween.Completed:Wait()
runServce.PreRender:Connect(function()
tweenService:Create(cam, tweenInfoCam3, {CFrame = CFrame.lookAt(cam.CFrame.Position, part.CFrame.Position)}):Play()
end)
sound:Destroy()
end
local func = task.spawn(ballEvent1Client) -- runs the function above: does cinematic bars, increases fov, stops player movement, and slowly tilts camera towards object in sky
task.delay(15,function() -- waits 15 seconds after the script is ran to cancel that function as well as reset everything to normal
task.cancel(func)
Controls:Enable()
cinemamodule.cinematicDisable()
workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
workspace.CurrentCamera.FieldOfView = 70
end)
This is my client sided script which essentially does what I’ve written in the notes. The resetting works for everything except the tween as the game stills tries to tween to the object since I guess it’s still running. I have some ideas on what I could do but I’d rather get another opinion for this.
Every :Connect()
method returns a RBXScriptConnection, which you can assign it to a variable and :Disconnect()
the connection using it whenever you want:
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local cinemamodule = require(game.StarterPlayer.StarterCharacterScripts.cinemaModule)
local Controls = require(game.Players.LocalPlayer.PlayerScripts.PlayerModule):GetControls()
local plr = game.Players.LocalPlayer
local part = game.Workspace:WaitForChild("ball") -- Put this back in the function if the ball is created between script loading and the function running.
local tweenInfoCam = TweenInfo.new(1.5, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
local tweenInfoCam2 = TweenInfo.new(3, Enum.EasingStyle.Quad, Enum.EasingDirection.InOut)
local tweenInfoCam3 = TweenInfo.new(1, Enum.EasingStyle.Sine)
local preRenderConnection -- Create an empty variable for the connection
local function ballEvent1Client()
local sound = Instance.new("Sound")
sound.Parent = game.SoundService -- Parenting created instances is recommended to parent them outside the new() function for performance reasons.
sound.SoundId = "rbxassetid://836142578"
sound.Volume = 2
local cam = game.Workspace.CurrentCamera
task.wait(3)
cinemamodule.cinematicBars()
Controls:Disable()
cam.CameraType = Enum.CameraType.Scriptable
sound:Play()
local tweenCam = TweenService:Create(cam, tweenInfoCam, {FieldOfView = 90}) -- default is 70
tweenCam:Play()
local preTween = TweenService:Create(cam, tweenInfoCam2, {CFrame = CFrame.lookAt(cam.CFrame.Position, part.CFrame.Position)})
task.wait(2)
preTween:Play()
preTween.Completed:Wait()
preRenderConnection = RunService.PreRender:Connect(function() -- Assign the connection.
cam.FieldOfView = 90
TweenService:Create(cam, tweenInfoCam3, {CFrame = CFrame.lookAt(cam.CFrame.Position, part.CFrame.Position)})
end)
sound:Destroy()
end
local func = task.spawn(ballEvent1Client)
task.delay(5,function()
preRenderConnection:Disconnect() -- Disconnect the connection.
task.cancel(func)
Controls:Enable()
cinemamodule.cinematicDisable()
workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
workspace.CurrentCamera.FieldOfView = 70
end)
Make sure you have created the variable outside of the ballEvent1Client()
function, so the task.delay()
function can access it.
I have also changed the script so we get some stuff outside of the function since we don’t neet to get them every time the function runs because they are not subject to change.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.