I need help with Camera script.
How i can make it smooth follow player
like here.
use TweenService to tween the camera
my quick example (not recommended to use this exact script):
wait(2)
local tweenService = game:GetService("TweenService")
local camera = workspace.CurrentCamera
local info = TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0)
camera.CameraType = Enum.CameraType.Scriptable
while wait() do
local root = game.Players.LocalPlayer.Character:FindFirstChild("HumanoidRootPart")
if root then
if root.Parent.Humanoid.MoveDirection.Magnitude >= 1 then
local goal = {CFrame = (root.CFrame * CFrame.new(0,2,5))}
local tween = tweenService:Create(camera,info,goal)
tween:Play()
end
else
break
end
end
what it looks like:
smth like this, but i need rotate camera as well.
rotate camera? Like being able to rotate camera while the camera is following the player? well if that’s what you’re looking for then I don’t know, I’m not good with these camera stuff.
Yeah like this, also same here, working with camera its hard.
You could use a BodyPosition inside a part that follows the char and set the camera’s CameraSubject
:
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local root = character:WaitForChild("HumanoidRootPart")
local cam = workspace.CurrentCamera
local camPart = Instance.new("Part")
camPart.Size = Vector3.new(1, 1, 1)
camPart.CanCollide = false
camPart.Name = "CameraFollowPart"
camPart.CFrame = root.CFrame * CFrame.new(0, 1.5, 0)
local bp = Instance.new("BodyPosition")
bp.Parent = camPart
camPart.Parent = character
cam.CameraSubject = camPart
game:GetService("RunService").Stepped:Connect(function()
bp.Position = root.Position + root.CFrame.UpVector * 1.5
end)
Nvm guys, thanks for pointing me out, I managed to do it. Thanks for helping.
Edit: Forgot about solution.
Ok so my solutio was.
Running RenderStepped OnUpdate function with CFrame calculating with :Lerp() to add smoothness.
To rotate camera i need use :GetMouseDelta() function of UserInputService
uis.InputChanged:Connect(function(Input, Bool)
if Bool == false then
if Input.UserInputType == Enum.UserInputType.MouseMovement then
local Delta2 = uis:GetMouseDelta()
--DeltaX, DeltaY = Delta2.X, Delta2.Y
--print(DeltaX, DeltaY)
--print(Input.UserInputType)
if DeltaX ~= Delta2.X then
--print(Delta2.X)
DeltaX = Delta2.X
end
if DeltaY ~= Delta2.Y then
--print(Delta2.Y)
DeltaY = Delta2.Y
end
end
end
end)
how exactly did you control the camera or at least figure out where it was going to do the learp calculations?
damn 2 years
didnt notice