New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Still have questions? Join our Discord server and get real time help.
1

What is lookVector and how do I use it?

Teeter11 260
4 years ago

I am very confused with it.

I know that it is the facing direction of a part. But the wiki doesn't say much more about it.

And how do i use it?

Thanks!

9

Well, to put it simply, lookVector is a Unit Vector of the direction of a CFrame.

You get the lookVector by added .lookVector to the end of a cframe value, like so:

local LookVector1 = Brick.CFrame.lookVector
--OR
local LookVector2 = (CFrame.new(0, 5, 0) * CFrame.Angles(0, math.rad(90), 0)).lookVector
--OR
local LookVector3 = CFrameValue.Value.lookVector


LookVector is useful if you want to make a part face a specific direction or you want to make an object travel in a specific direction. I will give 1 example:

Example: Making a bullet travel

Now if you want to make an effective gun, you need to make the bullets coming out of the gun travel in the direction that the gun is facing. In order to do so, you set the velocity of the brick as the direction that the gun is facing. So, in simpler terms, you have to use the lookVector of the handle:

Bullet.Velocity = Handle.CFrame.lookVector * 100 --By multiplying the lookVector by 100, I'm making the magnitude of the vector 100 which gives the bullet a speed of 100 in whatever direction the handle is facing


The code above will make the Bullet travel in whatever direction that the handle is facing at about 100 studs per second

There are obviously much more ways that you can use lookVector, but this is just 1, and it's pretty useful. Hope this helped!

0
thank u so much !! Teeter11 260 — 4y