Good day, I am experiencing issues with smoothly transitioning my camera from point A to point B. For example, my camera is at Vector3.New(0,2,0) and I am trying to take it to Vector3.New(2,0,-2). If it is fine, I would like the camera to slow down as it approaches the desired location. For your reference, I have offset the camera from the humanoid. I have tried tweening the camera with no luck, I have also tried lerping it with scripts I found on Forums with no luck. Any help is greatly appreciated as for I am a rookie to scripting, please tell me if I need to clarify anything. Thanks!
You could set the Camera
's CameraType
to Scriptable
Then set the CameraSubject
to Workspace.
Then tween it with TweenService
. Check easings.net for some easing styles.
After that revert the properties.
Well the moment I set it to scriptable it stopped following my character, sorry if it wasn’t clear that I’m working with a StarterCharacter. Its more of ease the camera when the player switches pov’s, not a cutscene. look at the video below to see what I mean.
If this helps you:
I already made the shiftlock system. If you see in the video, when I change camera positions, it is smooth, I am trying to do the same thing. Thanks.
Yes. As I said, the module should help you; as you can read the way it smoothly transitions the Camera’s offset and mimic it.
Alright, I’ll take a look, thank you!
If you’re willing to reprogram some of roblox’s default camera scripts then the way I did it with my camera system was I had a Vector3Value which contained the camera’s current offset to the player. Then I bound RunService.RenderStepped to set the camera’s position to that value. The reason the value is in a Vector3Value instance is so you can tween it smoothly.
Here’s a lot of example code.
local UserInputService = game:GetService('UserInputService')
local RunService = game:GetService('RunService')
local Players = game:GetService('Players')
local UserGameSettings = UserSettings():GetService("UserGameSettings")
local player = Players.LocalPlayer
local camera = workspace.CurrentCamera
local xAngle = 100
local yAngle = -15
local cameraPos = script.CameraOffset -- Vector3Value
local hold;
local defaultOffset = Vector3.new(0,0,5)
local isFirstPerson = false
local shiftLock = false
local currentAnimation = game:GetService('TweenService'):Create(cameraPos,TweenInfo.new(.3),{Value = Vector3.new(0,0,0)});
function updateCameraPos(vector) -- when we update the camera's offset, we can use this to make it smooth
currentAnimation = game:GetService('TweenService'):Create(cameraPos,TweenInfo.new(.3),{Value = vector})
currentAnimation:Play()
end
-- Handle inputs and detect when player holds right click to start moving their camera, mimics roblox's default camera scripts
UserInputService.InputBegan:Connect(function(input)
local inputType = input.UserInputType
if inputType == Enum.UserInputType.MouseButton2 then
hold = true
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
end
end)
UserInputService.InputChanged:Connect(function(input)
local inputType = input.UserInputType
if inputType == Enum.UserInputType.MouseWheel and not hold then
if input.Position.Z > 0 then -- this instantly goes between first and third person, but you could allow some zooming out before hitting the first person limit?
isFirstPerson = true
updateCameraPos(Vector3.new(0,0,0))
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
UserGameSettings.RotationType = Enum.RotationType.CameraRelative
else -- you may need to add additional scripts to hide the player character/head in first person.
isFirstPerson = false
updateCameraPos(Vector3.new(0,0,5))
UserInputService.MouseBehavior = Enum.MouseBehavior.Default
UserGameSettings.RotationType = Enum.RotationType.MovementRelative
end
end
end)
UserInputService.InputEnded:Connect(function(input)
local inputType = input.UserInputType
if inputType == Enum.UserInputType.MouseButton2 then
hold = false
UserInputService.MouseBehavior = Enum.MouseBehavior.Default
end
end)
camera.CameraType = Enum.CameraType.Scriptable
UserInputService.InputChanged:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement and (hold or isFirstPerson) then
xAngle = xAngle-input.Delta.x*0.4
yAngle = math.clamp(yAngle-input.Delta.y*0.4,-80,80)
end
end)
RunService.RenderStepped:Connect(function()
local Character = player.Character
local rootPart = Character:FindFirstChild("HumanoidRootPart")
if Character and rootPart then
local targetPart = rootPart;
local startCFrame = CFrame.new((targetPart.CFrame.p + Vector3.new(0,2,0)))*CFrame.Angles(0, math.rad(xAngle), 0)*CFrame.Angles(math.rad(yAngle), 0, 0) -- sets the camera to be at about the head, and looking at the direction we tracked
local cameraCFrame = startCFrame + startCFrame:vectorToWorldSpace(Vector3.new(cameraPos.Value.X,cameraPos.Value.Y,cameraPos.Value.Z)) -- offsets the camera
local cameraFocus = startCFrame + startCFrame:vectorToWorldSpace(Vector3.new(cameraPos.Value.X,cameraPos.Value.Y,-50000))
camera.CFrame = CFrame.new(cameraCFrame.p,cameraFocus.p)
else
xAngle = 100
yAngle = -15
end
end)
This mimics roblox’s default camera with a smooth first/third person transition but you can expand it further to include things like right/left shoulder view.
https://gyazo.com/8de9fa9a7476470f6c3e12e44d89c43c
Here’s what I did using a similar setup (r to switch shoulders, right click to shift lock/aim)
https://gyazo.com/9b443fff8a19546aaaebda389952029d
It turns out the code that I developed worked perfectly fine, a different part of the script was interfering with it, sorry. Thanks for the help though!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.