Vector3: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Mindraker
Vector3
>Outofspace
No edit summary
Line 1: Line 1:
A Vector3 has three values, an X ordinate, Y ordinate and Z ordinate. It represents a position in 3D space, and can be in World coordinates, Object coordinates, or anything that needs to have a set of three values in order to function.
Vector3 handles inputs that need three values. It's not a hard concept once you get passed that.


Vector3 has three values, an X ordinate, Y ordinate and Z ordinate. It represents a position in 3D space, just as a coordinate plane that you use in school, and can be in anything that needs to have a set of three values in order to function. (For example an object [[Position (Property)|position]], [[Size (Property)|size]], et cetera).


All properties are read-only.
 
All [[Property|properties] are read-only. However, they can be changed via [[Script|scripts]].
{| border="1"
{| border="1"
! Property !! Type !! Description
! Property !! Type !! Description
Line 19: Line 21:


==Vector3==
==Vector3==
Vector3 defines position. Learning Vector3 is the first step to learning how to teleport a brick and/or a character. It is three vectors -- x, y, and z. 
Vector3 is three values. An X (Horizontal), a Y (Vertical), and a Z (Depth). Learning Vector3 is the first step to learning how to move a brick and/or a character.


Example:
Example:


A brick is on the position line of 0,10,0.  It has three vectors.  Now let's convert it to Vector3.
A brick is on the position line of 0,10,0.  It has three vectors (x=0, y=10, z=0).  Now let's convert it to Vector3.


<pre>
<pre>
pos = Vector3.new(0,10,0)
pos = Vector3.new(0,10,0)
</pre>
</pre>
You don't need to put it in a variable, it is just that a variable is much easier to use.  I will teach you about "Vector3.new" later on.  You see the term "Vector3.new", then 3 numbers seperated by commas inside two parentheses.  The "0" is the x vector, the "10" is the y vector, and the other "0" is the z vector. X goes left to right (horizontal), Y goes up and down (vertical), Z goes in and out (depth).
 
You don't need to put it in a variable, it is just that a variable is much easier to use.  I will teach you about "Vector3.new" later on.  You see the term "Vector3.new", then 3 numbers seperated by commas inside two parentheses.  The "0" is the x vector, the "10" is the y vector, and the other "0" is the z vector (Vector3.new(x, y, z).
 


===Creating New Vectors===
===Creating New Vectors===
So now you want to teleport bricks. In the last segment, I told you about something called "Vector3.new". What it does is what it says, creates a new Vector3. When changing an object's position, you either use [[CFrame]] or "Vector3.new."
So now you want to teleport bricks? Here, we'll talk about "Vector3.new". When changing an object's position, you either use [[CFrame]] or "Vector3.new".
 
<pre>
<pre>
brick = game.Workspace.Brick
brick = game.Workspace.Part
brick.Position = Vector3.new(0,10,0)
brick.Position = Vector3.new(0,10,0) --Sets the part's x, y, and z coordinates.
</pre>
</pre>
First is the variable.  Note what we are changing before the "=" sign, ".Position". Then we come to the "Vector3.new". Same as before, it is giving them new Vectors of x, y, and z, which is, in this case, a new position.
 
In that example, we have Vector3.new(0,10,0), where X=0, Y=10, and Z=0.  


== See Also ==
== See Also ==


[[CFrame]]
*[[CFrame]]
*[[Part]]
*[[Properties]]

Revision as of 11:57, 1 December 2008

Vector3 handles inputs that need three values. It's not a hard concept once you get passed that.

Vector3 has three values, an X ordinate, Y ordinate and Z ordinate. It represents a position in 3D space, just as a coordinate plane that you use in school, and can be in anything that needs to have a set of three values in order to function. (For example an object position, size, et cetera).


All [[Property|properties] are read-only. However, they can be changed via scripts.

Property Type Description
x number the x-coordinate
y number the y-coordinate
z number the z-coordinate
unit Vector3 a normalized copy of the vector
magnitude number the length of the vector


Vector3

Vector3 is three values. An X (Horizontal), a Y (Vertical), and a Z (Depth). Learning Vector3 is the first step to learning how to move a brick and/or a character.

Example:

A brick is on the position line of 0,10,0. It has three vectors (x=0, y=10, z=0). Now let's convert it to Vector3.

pos = Vector3.new(0,10,0)

You don't need to put it in a variable, it is just that a variable is much easier to use. I will teach you about "Vector3.new" later on. You see the term "Vector3.new", then 3 numbers seperated by commas inside two parentheses. The "0" is the x vector, the "10" is the y vector, and the other "0" is the z vector (Vector3.new(x, y, z).


Creating New Vectors

So now you want to teleport bricks? Here, we'll talk about "Vector3.new". When changing an object's position, you either use CFrame or "Vector3.new".

brick = game.Workspace.Part
brick.Position = Vector3.new(0,10,0) --Sets the part's x, y, and z coordinates.

In that example, we have Vector3.new(0,10,0), where X=0, Y=10, and Z=0.

See Also