I’ll try to keep this short so its easy to understand what outcome I’m looking for.
What I want to happen is when a player has clicked a part, I’d like their camera to be gently forced to look towards the object for a couple of seconds.
I don’t want the player to be held completely static with no control, I’d prefer to have the players camera give some drag when the player attempts to look away, for example, the camera is being forced to look at a part, the player tries to drag their mouse away to look away from the object, however their camera is slowly dragged back to face the part.
The most I can think of would be using lookVector or something along those lines, however I wouldn’t know where to start.
local run = game:GetService("RunService")
local tweens = game:GetService("TweenService")
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local head = character:WaitForChild("Head")
local mouse = player:GetMouse()
local camera = workspace.CurrentCamera
local function onMouseButtonDown()
if mouse.Target then
local mouseTarget = mouse.Target
if mouseTarget:IsA("BasePart") then
local oldCamera = camera.CFrame
camera.CameraType = Enum.CameraType.Scriptable
local mousePosition = mouse.Hit.Position
local direction = (mousePosition - head.Position).Unit
local tween = tweens:Create(camera, TweenInfo.new(1.5), {CFrame = CFrame.lookAt(head.Position + direction * 2, mousePosition)})
tween:Play()
tween.Completed:Wait()
local connection = run.RenderStepped:Connect(function()
camera.CFrame = CFrame.lookAt(head.Position + direction * 2, mousePosition)
end)
task.wait(1.5)
connection:Disconnect()
local tween = tweens:Create(camera, TweenInfo.new(1.5), {CFrame = oldCamera})
tween:Play()
tween.Completed:Wait()
camera.CameraType = Enum.CameraType.Custom
end
end
end
mouse.Button1Down:Connect(onMouseButtonDown)
Feel free to play around with the values until you reach the desired result. I can provide further support/modifications if needed, just let me know.