Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What is lookVector and how do I use it?

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!

1 answer

✓ Accepted answer

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!

1 comment

1

thank u so much !!

This discussion is preserved as it was. New answers, comments, and votes are closed.