IoIiderp
|
  |
| Joined: 05 Feb 2012 |
| Total Posts: 8613 |
|
|
| 16 Mar 2015 12:18 PM |
| Its in raycasting but idk what it does and why there is *500 ? |
|
|
| Report Abuse |
|
|
|
| 16 Mar 2015 12:20 PM |
.Unit makes the largest vector become 1. So if the largest vector is 237, every vector gets divided by 237. If the largest vector is 0.4, every vector gets divided by 0.4. * 500 makes it 500 studs long. If you didn't use .Unit, if would be the length of the vector * 500, instead of 500 studs. |
|
|
| Report Abuse |
|
|
IoIiderp
|
  |
| Joined: 05 Feb 2012 |
| Total Posts: 8613 |
|
|
| 16 Mar 2015 12:29 PM |
So this is used for making a vector a ray? Because I think a ray will go like this: Start pos, way the ray goes.
And unit makes the second vector the way it goes? |
|
|
| Report Abuse |
|
|
|
| 16 Mar 2015 12:30 PM |
| No. Read the wiki on what the Unit property is. |
|
|
| Report Abuse |
|
|
IoIiderp
|
  |
| Joined: 05 Feb 2012 |
| Total Posts: 8613 |
|
| |
|
|
| 16 Mar 2015 12:33 PM |
It's to get a unit direction. Ever heard of something along the lines of "Velocity is a vector. It has both force and direction?"
Well, we consider "magnitude" the force of the vector. The direction is only needed in unitary form, meaning we only need a max of 1 and a minimum of -1. You know that 1 means straight up in world form. But what does 2 mean? Even more straight? No. It's the same.
So .unit will get the direction of the vector, per say. You multiply the magnitude against it to get the original vector. |
|
|
| Report Abuse |
|
|
|
| 16 Mar 2015 12:34 PM |
Ugh. Thanks for nothing DrMathematica. I was just about to say the majority of that along with
Unit returns the vector with a Magnitude of 1. |
|
|
| Report Abuse |
|
|
samy22
|
  |
| Joined: 28 Sep 2008 |
| Total Posts: 2181 |
|
|
| 16 Mar 2015 01:05 PM |
Hi, i didn't really understand it first, but i've put it out in baby steps for you for your understanding. Say you have two points and you want to calculate how much you increase their x, y and z positions by to move one point 1 stud closer to another point. That is where .unit comes in.
Example with 2 dimensions: (just x and y). Imagine a triangle with a base of length 4cm and a height of 3cm.
---/| --/-| 3cm -/--| ___| 4cm
Imagine the bottom left corner of the triangle as point 1 and the top right corner of the triangle as point 2. How do you calculate how much point1's x value has to increase by as well as it's y value for it to reach point2? You would just add 4 in the x direction and 3 in the y direction. But say if we wanted it to move only 1 stud at at a time in the direction heading towards point2... Then, we use .unit calculations. The length of the hypotenuse using Pythagorean theorem is math.sqrt(3^2 + 4^2) = math.sqrt(9 + 16) = math.sqrt(25) = 5. So the length from point 1 to point 2 is 5 studs. To make that 1 stud, we just do 5 divided by 5 which equals 1. To make it proportional, we divide the x value and the y value by 5 too. We now get, 4/5 cm and 3/5 cm. So the unit vector (x,y) is (4/5, 3/5) as it is 2D which increases by 1 stud in the direction from point1 to point2 if you add 4/5 to it's x value and 3/5 to it's y value. Even if you do math.sqrt((4/5)^2 + (3/5)^2) you'll get 1. This is why we say a unit vector has magnitude 1 always. You can multiply this by 500 to make it move 500 studs in the direction from point1 to point2.
Apply these same rules to roblox studio which is 3D (three dimensions with x,y,z) and it works the same way with the distance in studs between two points being just math.sqrt(x^2 + y^2 + z^2) instead of math.sqrt(x^2 + y^2).
|
|
|
| Report Abuse |
|
|
| |
|
samy22
|
  |
| Joined: 28 Sep 2008 |
| Total Posts: 2181 |
|
| |
|
| |
|