Just recently decided to try out coding in ROBLOX, and it's been pretty fun! I pulled a third person script from one of the ROBLOX Developer articles and tweaked it, and I've got a pretty solid camera so far, custom poppercam and all.
Question is, I'm not sure how to implement a zoom in & out function through a scroll wheel. This is what I have set up so far:
local function cameraLock(character)
local startCFrame = CFrame.new((rootPart.CFrame.Position)) * CFrame.Angles(0, math.rad(cameraAngleX), 0) * CFrame.Angles(math.rad(cameraAngleY), 0, 0)
local cameraCFrame = startCFrame:ToWorldSpace(CFrame.new(cameraOffset.X, cameraOffset.Y, cameraOffset.Z))
local cameraFocus = startCFrame:ToWorldSpace(CFrame.new(cameraOffset.X, cameraOffset.Y, -10000))
camera.CFrame = CFrame.new(cameraCFrame.Position, cameraFocus.Position)
if(Popper == true) then -- Don't mind this, this is a custom poppercam.
local Ignore = {
rootPart.Parent
}
local CheckRay = Ray.new(rootPart.Position + cameraDefault, cameraCFrame.Position - rootPart.Position)
local HitPart, HitPosition, Normal = game.Workspace:FindPartOnRayWithIgnoreList(CheckRay, Ignore, false, true)
--print(Normal)
if HitPart then
camera.CFrame = (camera.CFrame - (camera.CFrame.Position - (HitPosition)) + ((player.Character.Head.Position - camera.CFrame.Position).Unit) * 0.372)
end
end
end
I use RunService.RenderStepped:Connect to get this to run at all times, with a separate function to hide and lock mouse control.
I did some digging, and I came up with two events to check if mousewheel up/down is being fired:
mouse.WheelForward:Connect(function(inputObject)
print("Wheel went forward!")
end)
mouse.WheelBackward:Connect(function()
print("Wheel went backward!")
end)
Thing is, I can't exactly insert this onto the former function, as it's being called on every frame. Testing it inside cameraLock() prints "Wheel went forward!" three hundred times, hahaha.
Should I keep using this? I'm not sure what other ways I can approach this. I'd take this to the ROBLOX Dev Forum but I'm not a member yet.
Any help is appreciated! Again, I'm still getting a grasp on LUA as a whole, concepts and all, so, that's another thing to keep in mind. Thanks!
