Combine Vector3 and LookVector (I do not get CFrames)

Hi! How would I combine these two things into a single CFrame:

CFrame.new(Vector3.new())
CFrame.LookVector

How do I combine these together?

CFrame.new(Vector3.new()) * CFrame.LookVector does not work. :frowning:

Do you mean make the LookVector longer? If so just add the position with the LookVector:

local LongerVector = Origin.Position + CFrame.LookVector * LengthInStudsToIncrease

No I mean use the Vector3’s position and the LookVector’s orientation to create a CFrame Value

Normally you would do like:
CFrame.new(Vector3.new()) * CFrame.Angles()

Except I want to replace CFrame.Angles() with CFrame.LookVector

You cannot create a CFrame from just a position and a LookVector; you need at least two PERPENDICULAR directional vectors (RightVector, UpVector, LookVector), since you can calculate the third needed directional vector by taking the cross product of the two of which you already have. You can create a CFrame by using CFrame.fromMatrix(position, rightVector, upVector, lookVector?). Notice how lookVector is optional; you don’t need to include the third directional vector because it can be calculated using the rightVector and upVector. Hope this helps!

6 Likes

I have tried that it doesnt work.

OP already explained that they want to use a predefined LookVector to create a new CFrame at a certain position, but which shares the orientation with said LookVector. I’ve already explained why this isn’t possible in my previous post since using only one directional vector (the LookVector) will have infinite solutions to what OP is attempting to do.

It’s possible, but the outcome will always assume the upVector is perpendicular to the lookVector in the direction of true Y.

If you don’t have any other vectors, and you are okay with this outcome, than just using the lookAt constructor is perfectly fine.

Your response proved the point of my post. The LookAt constructor uses Vector3.new(0,1,0) as a reference Vector from which the RightVector and UpVector are derived. In the end, you still need two directional vectors to achieve the end goal; the LookAt constructor just makes it easier by making the assumption that you want the CFrame to be oriented upright at all times. Also, just a note, the LookAt constructor has been deprecated for some time and shouldn’t be used for new work apparently the API reference page has changed and this is no longer the case. Cheers!

I also found out that this works too:

CFrame.new(Vector3.new(), Vector3.new() + CFrame.LookVector)

I just didn’t do that because its not required if the position vector is (0,0,0) , since a lookVector will always have a magnitude of non zero. But for any case with a non (0,0,0) position, yes, thats the way to do it.

1 Like