Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

1 comment

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.