Need help with Vector3.Unit?

Today I started learning with a YouTube tutorial about Raycasting , and I was making a Automated turret and there is a part of the script that uses Vector3.Unit that I just don’t understand. If anyone could explain/help me out with this it would really help because the person in the tutorial didn’t manage to explain what it does. :smiley:

  • Here is the entire script :

image
image
image

  • And here is the part that uses Vector3.Unit (I also do not understand what this entire line of code does.) :

image

And here is the definition from the wiki (which i don’t understand) : image

4 Likes

Do you know what a vector is? You need to know what a vector is to understand vector3. And I’m guessing you dont? Since the definition according to your screenshot, uses a vector to explain it. This also might help:

https://rbxlua.fandom.com/wiki/Vector3

1 Like

I understand Vectors well enough at least I think so.

Assuming that you are a beginner in scripting, I think that you should not use the tutorial, it will be insufficient. You are just taking the code and not learning anything new. Here are some helpful roblox wiki api article to help you understand ray casting and vectors:

Well, I mean the dev hub definition gives a good description of it, isn’t there an example in the post, can you link the vector3 hub article because I can’t find it for some reason. But if that doesn’t help you look at this:

https://rbxlua.fandom.com/wiki/Vector3

1 Like

A vector represents a direction and magnitude (length).

image

You can think of a vector as an arrow pointing in a certain direction that also has a length, in this case 2 units.

A unit vector is a vector that has a direction and a length of 1 unit.

image

When you call Vector3.Unit it copies that vector’s direction and sets its length to 1.

27 Likes

I wouldn’t say I’m a beginner at scripting probably intermediate/Newish but I understand Vector3 but i’m still gonna check these two articles out. And the trutorial was actually helpful and I understood it the problem is he didn’t manage to really cover the Vector3.Unit part. :slightly_smiling_face:

1 Like

The unit for example would the humanoid’s Move Direction. You will never see a number greater than 1 or less then -1 or in other words ‘Magnitude’. Unit is just so you know the direction, this would normally be used in cases like (Position).Unit * Length so you grab its position and just stretch the length or “magnitude” towards that direction.

3 Likes