# How does LookVector work?

Hello people!

I’ve been trying for 10 minutes to use the “lookVector” property of a CFrame, but it won’t work.
Tried everything. Basically, I want my part to go 5 studs forward. That’s it.

How to use lookVector?

-Meaxis

49 Likes

`LookVector` is a property of `CFrames` aka `Coordinate Frames` that represent the unit vector of the CFrame direction. If you’d like to construct your own CFrames with lookvectors, you can call `CFrame.fromMatrix`.

CFrame.fromMatrix ( Vector3 pos, Vector3 vX, Vector3 vY, Vector3 vZ )
Creates a CFrame from a translation and the columns of a rotation matrix. If vz is excluded, the third column is calculated as [vx:Cross(vy).Unit].

#### Finding a LookAt Vector

This example uses `CFrame.fromMatrix()` to create a CFrame located at eye with it’s lookVector pointing towards the target position.

``````function lookAt(target, eye)
local forwardVector = (eye - target).Unit
local upVector = Vector3.new(0, 1, 0)
-- You have to remember the right hand rule or google search to get this right
local rightVector = forwardVector:Cross(upVector)
local upVector2 = rightVector:Cross(forwardVector)
return CFrame.fromMatrix(eye, rightVector, upVector2)
end
``````

27 Likes

Look/Up/Right Vectors describe the direction of the Front/Top/Right faces.

``````-- Preferred way
-- moves it forward 5 studs (relative to it's orientation), forward is NEGATIVE on the Z-plane
part.CFrame = part.CFrame * CFrame.new(0, 0, -5)

-- Way using lookVector
-- If facing straight forward, lv is <0, 0, -1>
local cf = part.CFrame
local lv = cf.lookVector
part.CFrame = cf + (lv * Vector3.new(5, 5, 5))
``````
88 Likes

Okay. Thanks alot for your answer, but it’s really complicated, didn’t understand quite well even though I tried to test it in game, read the docs and read the script 8 times. CFrame isn’t my thing, but @Darkmist101 posted an easier-to-understand answer. Thanks alot for your answer tho.

5 Likes

Solved my problem! Marking as solution.

2 Likes

A direction is yes (target - eye) or then I can do that:

``````local Part = Istance.new("Part", workspace)
Part.Position = Vector3.new(0,10,0)
local eye = Part.Position
local target = Vector3.new(0,0,1)
wait(10)
Part.CFrame.LookVector = (eye - target)``````
16 Likes

I didn’t even realize that! I feel proud now

5 Likes