Annoying CFrame.fromMatrix complication

Hello, I’ve been trying to make slow view bobbing on the camera for a title screen, but my console gets spammed with errors and my camera stays in one spot, heres my code:

local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local Camera = workspace.Camera

local lockPart = workspace.CameraPart

Camera.CameraType = Enum.CameraType.Scriptable	
Camera.CFrame = lockPart.CFrame

local Tween = TweenService:Create(Camera,,Enum.EasingStyle.Sine),{
CFrame = CFrame.fromMatrix(
	repeat wait() until Tween.Completed

The error I get:

 15:51:10.293 - Players.DokuDako.PlayerGui.LocalScript:23: bad argument #3 (Vector3 expected, got no value)
15:51:10.294 - Stack Begin
15:51:10.294 - Script 'Players.DokuDako.PlayerGui.LocalScript', Line 23
15:51:10.295 - Stack End

I’ve been trying to look up info from other people on the developer forum and developer hub, but couldn’t really find any info on this.
Heres a video showcasing the bug:

If anyone can help, thanks!

1 Like

The only wrong thing, that I can see now is just this part.
Put there local Camera = workspace.CurrentCamera instead, but to be honest, I don’t think this will absolutly solve the problem.

1 Like

It didn’t really solve the problem, but thanks for the small suggestion though!

Have you tried CFrame =

The reason it isn’t working is because you are not providing the required third vector for fromMatrix to work.

You need at least three arguments. Fourth is optional.

Didn’t I apply the Z vector for the orientation? Whats going on?

Ah, just saw that quick edit there. I’m not really that advanced in Maths but I’ll try the vx:Cross(vy).Unit and try to notify you when it worked.

I don’t think you should be using fromMatrix for this. If you are trying to create camera bobbing, there is no need for fromMatrix.

1 Like

Oh, alright then.
I might as well use some other CFrames for that.

You should really only be using for that, since all you need to change is position.

So for bobbing, I would just have a position for wherever the camera starts. From there, you can subtract and add however much you want the camera to rise and fall from the Y axis of that position.

IE: If my camera starts at,5,0), and I want it to fall and rise 2 studs, then I’ll store four variables.

StudDifference = 2
InitialCameraPosition = Camera.CFrame.Position (,5,0) )

HighExtreme = InitialCameraPosition +,StudDifference,0)
LowExtreme = InitialCameraPosition -,StudDifference,0)

Then you can just tween to a CFrame that has one or the other value at a time as its position.

Tween to , then Tween to , and repeat.

This is the general idea. Depending on what you are doing, you will need to swap some things out here and there to make it work correctly for the scenario.

1 Like

Understood, thank you for your help!