Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
5

What is lookVector and how do I use it? [closed]

Asked by
Teeter11 281 Moderation Voter
9 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!

Locked by JesseSong

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

1 answer

Log in to vote
21
Answered by 9 years ago

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
thank u so much !! Teeter11 281 — 9y
Ad