When the Dialogue trigger is triggered, I want my camera to look at (Without changing its position and without changing its CameraSubject) the NPC and I want the camera to slightly zoom in. (I already know how I would go on about smoothly zooming in using Camera’s Field of View.) But how would I go on about making the camera look at the NPC without moving the Camera’s Position? (Basically I want the camera to smoothly change its orientation (I want it to look directly at the NPC) but I don’t want to change the camera’s position.)
The result should look something like this:
Alright, so after some digging around I eventually found out how I would do this,…
local IsTalking = false
local Camera = game.Workspace.CurrentCamera
NPC_HumanoidRootPart = ...
...
RunService.RenderStepped:Connect(function() -- On Every Frame
if IsTalking and NPC_HumanoidRootPart then -- Checks if the player is talking to the NPC and if NPC_HumanoidRootPart exists.
Camera.CameraType = Enum.CameraType.Scriptable -- When the camera is set to scriptable, it doesn't move, and the player can't control it anymore unless you script it so the player can control it.
Camera.CFrame = Camera.CFrame:Lerp(CFrame.lookAt(Camera.CFrame.Position, NPC_HumanoidRootPart.Position + Vector3.new(0,0,0)), 0.07)
TweenService:Create(Camera, TweenInfo.new(2), {FieldOfView = 45}):Play() -- Zooms in the camera.
end
end)
I don’t know if this is a good way to do this, but it does the job.
That’s where you would put your NPC’s Humanoid Root Part…
For example, if your NPC was in workspace, under a Folder named NPCs you would put: NPC_HumanoidRootPart = game.workspace.NPCs. (NPC's name) .HumanoidRootPart
If you are talking about the … above the RunService.RenderStepped:Connect(function(), that’s where I had additional code. Since I have multiple NPCs, and I have only one Local Script in StarterGUI, when the Trigger is activated, there is a special RemoteEvent which sends me that NPCs Humanoid Root Part to that Local Script in the StarterGUI (PlayerGUI), so I don’t have to search for the NPC’s Root Part manually.