Basically I am making a camera fix script. I want the camera to tween back to behind the player… but when I try to do so, the camera does not go to the player. It will face the direction the player is facing like it is supposed to but it should also tween to behind the player so I was just wondering how I could go about doing so.
local TweenService = game:GetService("TweenService")
local goals, tweenInfo, tweens = {}, {}, {} --Used for tween service.
-------------------------------------------:
--Reset the frame:
--Set camera to face the same direction as player
goals[1] = {}
goals[1].CFrame = CFrame.lookAt(game.Workspace.CurrentCamera.CFrame.Position, game.Workspace.CurrentCamera.CFrame.Position + game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame.LookVector)
tweenInfo[1] = TweenInfo.new(
0.5, --tween length
Enum.EasingStyle.Quint, --easing Style
Enum.EasingDirection.Out --easing Direction
)
tweens[1] = TweenService:Create(game.Workspace.CurrentCamera, tweenInfo[1], goals[1])
game.Workspace.CurrentCamera.CameraType = "Scriptable"
tweens[1]:Play()
tweens[1].Completed:Wait()
Your goal CFrame is the cause of this. You should probably just use CFrame.new().
local hrp = game.Players.LocalPlayer.Character.HumanoidRootPart
local camera = workspace.CurrentCamera
local tgtCamPos = hrp.Position * Vector3.new(1, 0, 1) + camera.Position * Vector3.yAxis -- Set tgtPos to hrp at current cam altitude (looks like thats they way you have it)
tgtCamPos -= hrp.CFrame.LookVector * OFFSET
goals[1] = {
CFrame = CFrame.new(tgtCamPos, hrp.Position)
}
EDIT: More changes incoming, accidentally tabbed and it sent the message. NOTE: This might not be the correct way to position it the way you want it to be positioned, but using CFrame.new() is the way to go.
You should consider using Lerp() function in this case.
You must use the fact that you know how big step will be for the lerp. (1-(NextStepCFrame-CF2).Magnitude)/((C2-CF2).Magnitude)