#camera trigger

1 messages · Page 1 of 1 (latest)

unkempt latch
#

im trying to script a part where when i touch it, it will trigger the camera to snap onto a different object.

magic knoll
#

Just ask chatgpt to make a template script for that

prisma parrotBOT
#

studio** You are now Level 2! **studio

gentle beacon
#

You will have to change the CameraType to scriptable in order to do this so make sure to reset it when your done with manipulating the camera

unkempt latch
# gentle beacon Use a TouchEvent listener on the part, add a conditional to ensure it was a play...

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local remote = ReplicatedStorage:WaitForChild("CameraSnapEvent")
local player = Players.LocalPlayer
local camera = workspace.CurrentCamera

local originalType = nil
local originalSubject = nil

remote.OnClientEvent:Connect(function(targetPosition, duration)
-- Save original camera state
originalType = camera.CameraType
originalSubject = camera.CameraSubject

-- Set camera to Scriptable and focus on target
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = CFrame.new(camera.CFrame.Position, targetPosition)

-- Optionally, smoothly update camera to keep looking at target
local startTime = tick()
local conn
conn = RunService.RenderStepped:Connect(function()
    local now = tick()
    if now - startTime > duration then
        conn:Disconnect()
        -- Restore camera
        camera.CameraType = originalType
        camera.CameraSubject = originalSubject
        return
    end
    camera.CFrame = CFrame.new(camera.CFrame.Position, targetPosition)
end)

end)

#

is that a good one?