Ad
Log in to vote
0

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

Asked by 9 days 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?

Hi.

Looks like you're using an ad blocker.

That's fine...

No, it really is.

Just, I mean, we put a lot of work into this site, you know?

It would be really really appreciated if you would turn off your ad blocker for our website...

We tried really hard to make our ads as unobtrusive as possible.

If you really hate ads, would you consider a $2 donation via Patreon?

Here's the link.

We love you. We hope you love us too.

.

..

...

Now back to your regularly scheduled Scripting Helpers....

...

..

.

1 answer

Log in to vote
1
Answered by
Azarth 1866
9 days ago
Edited 9 days 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 79 — 9d
Ad

Answer this question



Ad