Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is there a way to smoothly move the player's camera position?

Asked by 4 years ago

In my game, I want the camera to zoom in when you aim with a gun. This is simple to do, but just changing the FOV or zoom distance values is choppy. Is there a way to smoothly do this?

1 answer

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

Maybe use TweenService.

local cam = game.Workspace.CurrentCamera
local mouse = game.Players.LocalPlayer:GetMouse()
local TweenService = game:GetService("TweenService")
local debounce = false
local aiming = false
local t= .3

local info = TweenInfo.new(t, Enum.EasingStyle.Linear,Enum.EasingDirection.In,0,false,0) --(time,easingStyle,EasingDirection,NumberOfRepeats,canRepeat,delay)

local Forward = { FieldOfView = 60  } -- change right side of equation to whatever
local Backward = {FieldOfView = 70 }

local zoomIn = TweenService:Create(cam,info,Forward) -- these create the tweens
local zoomOut = TweenService:Create(cam,info,Backward)

mouse.Button2Down:Connect(function() --change this to whatever makes the player aim
    if debounce == false then
        debounce = true
        zoomIn:Play() -- this plays the tween
    end
end)
mouse.Button2Up:Connect(function()
    if debounce == true then
        debounce = false
        zoomOut:Play()
    end
end)

Look up tweening if you want to learn more. Also, don't forget to mark this as the answer!

0
I thought I might be able to use tweenservice, just wasn't sure it supported camera movement. Lemme try it then vouch. DejaSketch 84 — 4y
0
The second parameter of TweenService:Create() is the table of which property of the targeted instance should be tweened, and FieldOfView is a property of the camera, so it should work. OddExistent 52 — 4y
0
Is there any way to move the camera slightly to the right as well? It's a third person game, so I want it to hover over their shoulder. DejaSketch 84 — 4y
0
Search up camera manipulation, then you will find your answer. OddExistent 52 — 4y
Ad

Answer this question