-
What do you want to achieve?
Basically I’m making a custom camera for my game, to follow the player’s movement and orientation -
What is the issue?
When the player goes backwards, camera goes crazy due to a loop happening where the camera moves along and the player goes backwards respecting the camera orientation. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried a few solutions but none worked.
This is the piece of code that modifies the camera
_G.Zoom = 20 --just for example
local cameraOffset = Vector3.new(0, _G.Zoom-6, _G.Zoom/2)
local characterPosition = Character.HumanoidRootPart.Position
local characterLookVector = Character.HumanoidRootPart.CFrame.LookVector
local lookAtPoint = characterPosition + Vector3.new(0, 8, 0)
local desiredCameraPosition = characterPosition - (characterLookVector * cameraOffset.Z) + Vector3.new(0, cameraOffset.Y, 0)
if not lastCameraPosition then
lastCameraPosition = desiredCameraPosition
else
if (desiredCameraPosition - lastCameraPosition).Magnitude > 0.3 then
lastCameraPosition = lastCameraPosition:Lerp(desiredCameraPosition, 0.008)
end
end
Camera.CFrame = CFrame.new(lastCameraPosition, lookAtPoint)