Dot product returning number?

so i am trying to get the projection of a vector to another and the code looks like this:

local CameraDirection 	= rootPart.CFrame:toObjectSpace(camera.CFrame)
		local RootCF		  	= rootPart.CFrame
		
		local CL = CameraDirection.LookVector 	--Camera Lookvector
		local CR = CameraDirection.RightVector 	--Camera RightVector
		local CU = CameraDirection.UpVector		--Camera UpVector
		
		local RL = RootCF.LookVector			--Root LookVector
		local RR = RootCF.RightVector			--Root RightVector
		local RU = RootCF.UpVector				--Root UpVector
		
		---time to project camera vectors onto the RootPart's planes
		
		local ProjectedL = CL - ((CL:Dot(RR)) / (CL.Magnitude * RR.Magnitude))

and i’m getting this beautiful message:

Players.Temeraire149.PlayerScripts.LocalScript:38: attempt to perform arithmetic (sub) on Vector3 and number 

--that's this line:
--local ProjectedL = CL - ((CL:Dot(RR)) / (CL.Magnitude * RR.Magnitude))

the vector is CL and the number, by elimination is the Dot product

I don’t know what I did wrong so I’m asking for help
Thanks,
Tem

local CameraDirection 	= rootPart.CFrame:toObjectSpace(camera.CFrame)
		local RootCF		  	= rootPart.CFrame
		
		local CameraLookVector = CameraDirection.LookVector 	--Camera Lookvector
		local CameraRightVector = CameraDirection.RightVector 	--Camera RightVector
		local CameraUpVector = CameraDirection.UpVector		--Camera UpVector
		
		local RootLookVector = RootCF.LookVector			--Root LookVector
		local RootRightVector = RootCF.RightVector			--Root RightVector
		local RootUpVector = RootCF.UpVector				--Root UpVector
		
		---time to project camera vectors onto the RootPart's planes
		
		local ProjectedL = CameraLookVector - ((CameraLookVector:Dot(RootRightVector)) / (CameraLookVector.Magnitude * RootRightVectorR.Magnitude))

^^ For easier readability!

Essentially, you’re trying to remove CFrame and Vector3 from each other, which will most likely return this error. (However, I don’t exactly know if that statement is true, but it pieces together between the error and CameraDirection.)

You’ll have to find an alternative way to make them both Vector3, or scrap the product, as there really is no other solution.

Hopefully this helps! :grin:

1 Like

You should draw a little diagram of what you’re trying to achieve here, it’s a bit unclear what you are trying to do

https://gyazo.com/7b4545ecc90a2f37868dc68663cf2e6d

I found the problem. It was my wrong perception about DotProduct. The dot product returns the module of the projection on the vector.
So, to solve it, we use v1:Dot(v2) * v2.Unit

1 Like