Vector3: Difference between revisions

From Legacy Roblox Wiki
Jump to navigationJump to search
>Outofspace
No edit summary
>Mr Doom Bringer
No edit summary
Line 17: Line 17:
|-
|-
| <code>magnitude</code>|| number ||| the length of the vector
| <code>magnitude</code>|| number ||| the length of the vector
|}
{| border="1"
! Member Function !! Description
|-
| <code>Vector3 lerp(Vector3 goal, number alpha)</code> || returns a Vector3 lerped between this Vector3 and the goal. alpha should be between 0 and 1
|}
|}



Revision as of 20:12, 23 February 2010

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
Member Function Description
Vector3 lerp(Vector3 goal, number alpha) returns a Vector3 lerped between this Vector3 and the goal. alpha should be between 0 and 1


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