Vector3: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Mindraker
feel free to alter this however you want...
>Mindraker
Vector3
Line 18: Line 18:




<b>Position:</b> <b>r</b><i>t</i> = <i>x(t)</i><b>i</b> + <i>y(t)</i><b>j</b> +<i>z(t)</i><b>k</b><br>
==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


<b>Velocity:</b> <b>v</b><i>t</i> = (<i>d</i><b>r</b>/<i>dt</i>) = (<i>dx/dt</i>)<b>i</b> + (<i>dy/dt</i>)<b>j</b> + (<i>dz/dt</i>)<b>k</b>
Example:


<b>Speed:</b> ||<b>v</b><i>(t)</i>|| = sqrt((<i>dx/dt</i>)^2 + (<i>dy/dt</i>)^2 + (<i>dz/dt</i>)^2)
A brick is on the position line of 0,10,0.  It has three vectors.  Now let's convert it to Vector3.


<b>Acceleration:</b> <b>a</b><i>(t)</i> = <i>d</i><b>v</b>/dt = <i>d^2</i><b>r</b>/<i>dt^2</i> + (<i>(d^2x)/(dt^2)</i>)<b>i</b> + (<i>(d^2y)/(dt^2)</i>)<b>j</b> + (<i>(d^2z)/(dt^2)</i>)<b>k</b>
<pre>
pos = Vector3.new(0,10,0)
</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).
 
===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."
<pre>
brick = game.Workspace.Brick
brick.Position = Vector3.new(0,10,0)
</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. 
 
== See Also ==
 
[[CFrame]]

Revision as of 08:02, 4 November 2008

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.


All properties are read-only.

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 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.

Example:

A brick is on the position line of 0,10,0. It has three vectors. 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. X goes left to right (horizontal), Y goes up and down (vertical), Z goes in and out (depth).

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."

brick = game.Workspace.Brick
brick.Position = Vector3.new(0,10,0)

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.

See Also

CFrame