Only assumptions can be made from the snippet of code you provided. If you want the full answer, you need to provide the full snippet, which includes the unitRay variable
I am getting the position of the endpoint relative to the camera.
As if the camera was a (0, 0, 0), pointing down, and the endpoint was at (x, y, z). But instead, now the camera is in the sky at an angle looking sideways, and the endpoint was somewhere 500 studs away from it. If you don’t understand, I can explain further :D
Well, since you know what the inverse() of a CFrame is doing, essentially how it’s getting the offset by dot products:
-- // Uses the code from your makeRay function
local unitRay = camera:ViewportPointToRay(xVal,yVal)
local cast = workspace:Raycast(unitRay.Origin, unitRay.Direction, params)
local cf = camera.CFrame
local lookVector = cf.LookVector
local startPoint = cf.Position
local endPoint = startPoint + (unitRay.Direction*100)
-- // I replaced your `(CFrame.lookAlong( startPoint , lookVector ))`
-- // Part with just cf, as they essentially have the exact same CFrame
-- // Since you didn't enter the 3rd arguement in CFrame.lookAlong(pos, dir, relative_up)
local vekter = (CFrame.lookAlong( endPoint , lookVector ):Inverse() * cf).Position
-- // As you know endCF:Inverse() * startCF is *similar* to
-- // This in vector terms as they're both offsets
local offset = startPoint - endPoint
-- // Then you do the magic with the original CF you have
local right_vector = offset:Dot(cf.RightVector) -- // Relative X
local up_vector = offset:Dot(cf.UpVector) -- // Relative Y
-- // You have to flip look vector just because that's how it is I guess
local look_vector = offset:Dot(-cf.LookVector) -- // Relative Z
print(vekter, "<-- vekter")
print(Vector3.new(right_vector, up_vector, look_vector), "<-- other")
print("=============================")
Idk which is more performant but yeah, you can test that. ( :
I left your code in so you can copy pasta this into your makeRay function if you want and test for yourself.