Ad
Log in to vote
0

How do you make the camera zoom in using lerp function?

Asked by
Radstar1 225 Moderation Voter
11 months ago

I know this is a broad question, and I'm not asking you to make me a script that does 'this' and 'that'. However, what's the general idea behind that?

1 answer

Log in to vote
1
Answered by
Azarth 2051 Moderation Voter
11 months ago
Edited 11 months ago

Since you weren't pushy or asking for a script.. here's a simple script. Turn on LockFirstPerson.

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
local head = char:WaitForChild("Head")
local cam = workspace.CurrentCamera
local InputService = game:GetService('UserInputService')
local mouse = player:GetMouse()

local zooming = Instance.new("CFrameValue")

local function down()
    local target = mouse.Target
    if target then 
        cam.CameraType = Enum.CameraType.Scriptable
        zooming.Value = mouse.Hit
    end
end

local function up()
    cam.CameraType = Enum.CameraType.Custom
end

InputService.InputBegan:connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        down()
    end
end)

InputService.InputEnded:connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        up()
    end
end)

zooming.Changed:connect(function()
    -- zooms to the location of your mouse - (its lookVector*2) so
    -- it doesn't go inside the object
    -- I used lookVector because it retains the same rotation
    cam:Interpolate(CFrame.new(zooming.Value.p - (zooming.Value.lookVector * 2)), zooming.Value, .1)
end)
0
Bro this is amazing, I was just using it so in my cutscene it would zoom onto a specific target, but I can convert this. I didn't know you could use it with the mouse like that. Thank you so much. Radstar1 225 — 11mo
Ad

Answer this question