generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: what does .unit

Previous Thread :: Next Thread 
IoIiderp is not online. 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
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
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 is not online. 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
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
16 Mar 2015 12:30 PM
No. Read the wiki on what the Unit property is.
Report Abuse
IoIiderp is not online. IoIiderp
Joined: 05 Feb 2012
Total Posts: 8613
16 Mar 2015 12:30 PM
Okay thanks.
Report Abuse
DrMathematica is not online. DrMathematica
Joined: 29 Aug 2008
Total Posts: 27268
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
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
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 is not online. 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
DrMathematica is not online. DrMathematica
Joined: 29 Aug 2008
Total Posts: 27268
16 Mar 2015 01:18 PM
omg wat is that
Report Abuse
samy22 is not online. samy22
Joined: 28 Sep 2008
Total Posts: 2181
16 Mar 2015 01:19 PM
math
Report Abuse
DrMathematica is not online. DrMathematica
Joined: 29 Aug 2008
Total Posts: 27268
16 Mar 2015 01:19 PM
ok
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image