I am trying to focus to the paddle of my Atari brick out clone however I am unable to do it. I am trying to do it by using a script to focus to a focus part that is used to look at the paddle. The CFrame coordinate of the focus part are CFrame.new(-741, 107.5, -174.5, 1, 0, 0, 0, 1, 0, 0, 0, 1).
Here is how my attempt look like:
-- Services
local ReplicatedStorage = game.ReplicatedStorage
local Players = game.Players
local LocalPlayer = Players.LocalPlayer
-- Modules
local cameraModule = require(ReplicatedStorage.modules:WaitForChild("CameraModule_RTS"))
-- Code
--workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
local defaultCamX = 741.5 local defaultCamY = 100 local defaultCamZ = 0
local focusPart = workspace.focusPart
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
workspace.CurrentCamera:Interpolate(focusPart.CFrame, LocalPlayer.Character.PrimaryPart.CFrame, 4)
The issue with this attempt is that it’s not focusing on the right thing. Its supposed to be focusing at the paddle which is at the coordinate 741.5, 0, 0). It look like this in the game:
There are a couple of different ways you can do it.
One way is to change the CameraSubject to the Part you want to focus on then change the camera type. (Although this might not be what you want)
Or you can setup an offset for your Camera and then bind it to the frame RenderStepped.
Like this
local Part = workspace.Part
local RunService = game:GetService("RunService")
local Offset = Vector3.new(0,5,-10) --10 studs back and 5 studs up
local ZERO_VECTOR = Vector3.new() -- Need it as Camera needs to look directly at 0,0,0 at the part.
RunService:BindToRenderStep("UpdateCamera",Enum.RenderPriority.Camera.Value + 1,function(DeltaTime)
Camera.CFrame = Part.CFrame:ToWorldSpace(CFrame.lookAt(Offset,ZERO_VECTOR)) -- ToWorldSpace is a fancy method we use for offseting CFs relative to other CFs. Here we offset the Camera to the Part
end)
Result:
(I just attached the Camera to a dropped brick out of the sky)