So I have a script where the camera is positioned to a node to face something and a function to add like a camera following the mouse effect, the problem is that the camera always faces the origin no matter where I put the node it always faces the origin Ill provide examples below
-- Scene Camera Nodes
local LoadingScreen_Nodes: Folder = workspace:WaitForChild("LoadingScene_Nodes")
local RandomSceneNode: BasePart = LoadingScreen_Nodes:GetChildren()[math.random(1, #LoadingScreen_Nodes:GetChildren())]
local Mouse: Mouse = LPlayer:GetMouse()
-- Prepare Camera for Scene
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = RandomSceneNode.CFrame
-- Camera Follow at Mouse
CameraConnection = RunService.RenderStepped:Connect(function(deltaTime)
-- Get Look Position and Set
local Direction = (Mouse.Hit.Position - Camera.CFrame.Position).Unit * 50
Camera.CFrame = Camera.CFrame:Lerp(CFrame.new(Camera.CFrame.Position,Direction),.1)
end)
Are you sure that this is the only code that is moving the camera? From the video it looked like there might be something else moving the camera.
It looks like you are setting the position of the camera directly where your “node” is at.
I would specify an origin position and then get the CFrame from that. Then if you still want to follow the mouse then you can apply a transform to that CFrame.
For example, I made a similar camera during the pandemic.
| a → camera cframe | b → node cframe | c → b - a | u → unit c * n |
CFrame.new() with a second argument is the old way to define CFrame.lookAt(). If Direction, respectively u is the ‘look at’ position, it’s always originating from the origin of the coordinate system.
So we need camera’s position + direction. But because that comes without limits, we would have to clamp the angles.
If you don’t mind, I found a slightly easier approach to achieve the same effect, based on the screen mouse location.
local RunService = game:GetService("RunService")
local UIS = game:GetService("UserInputService")
local LocalPlayer = game:GetService("Players").LocalPlayer
local Camera = workspace.CurrentCamera
local Mouse = LocalPlayer:GetMouse()
local LoadingScene_Nodes: Folder = workspace.LoadingScene_Nodes
local RandomSceneNode: BasePart = LoadingScene_Nodes:GetChildren()[
math.random(1, #LoadingScene_Nodes:GetChildren())
]
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CameraSubject = nil
Camera.CFrame = RandomSceneNode.CFrame
RunService:BindToRenderStep("SceneCamera", Enum.RenderPriority.Camera.Value +1, function(dt)
local MouseLocation = UIS:GetMouseLocation()
local NewCFrame = RandomSceneNode.CFrame * CFrame.fromEulerAnglesXYZ(
math.rad(((MouseLocation.Y - Camera.ViewportSize.Y *.5)/Camera.ViewportSize.Y) * -20),
math.rad(((MouseLocation.X - Camera.ViewportSize.X *.5)/Camera.ViewportSize.X) * -15),
0
)
Camera.CFrame = Camera.CFrame:Lerp(NewCFrame, .1)
end)