I’m trying to recreate the spring based car camera that was shown in GDC 2020:
However I’m running into an issue where when I turn my car around,i t causes the camera to fling all over the place, I’m not exactly sure what is causing this.
My Code:
local CameraOffset = CFrame.new(0,4,16)
local springModule = require(game.ReplicatedStorage.Spring)
local positionSpring = springModule.new(Vector3.new())
local anglesSpring = springModule.new(Vector3.new())
local function getPositionAndAnglesFromCFrame(cf)
return cf.Position, Vector3.new(cf:ToEulerAnglesXYZ())
end
local function getCFrameFromPositionAndAngles(pos, ang)
return CFrame.new(pos) * CFrame.Angles(ang.X, ang.Y, ang.Z)
end
local function updateCamera()
positionSpring.d = workspace.Damping.Value
positionSpring.s = workspace.Speed.Value
anglesSpring.d = workspace.Damping.Value
anglesSpring.s = workspace.Speed.Value
local carCFrame = car.VehicleSeat.CFrame
local cameraCFrameGoal = carCFrame * CameraOffset
-- Convert camera cframe into linear spaces
local cameraPositionGoal,
cameraAnglesGoal = getPositionAndAnglesFromCFrame(cameraCFrameGoal)
--local previousCameraAnglesGoal = anglesSpring.t
--local cameraAnglesGoal = getClosestAngles(rawCameraAnglesGoal, previousCameraAnglesGoal)
positionSpring.t = cameraPositionGoal
anglesSpring.t = cameraAnglesGoal
local cameraPosition = positionSpring.p
local cameraAngles = anglesSpring.p
-- Convert back into cframe
local finalCameraCFrame = getCFrameFromPositionAndAngles(
cameraPosition,
cameraAngles
)
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
workspace.CurrentCamera.CFrame = finalCameraCFrame
end
I think it may have to do with the missing function getClosestAngles that was shown in the GDC video, but I have no idea what formula was used to figure this out.