Vector3: Difference between revisions
>Blocco No edit summary |
>NXTBoy |
||
Line 32: | Line 32: | ||
In the Command Line, type in this bit here and hit enter: | In the Command Line, type in this bit here and hit enter: | ||
{{CodeExample}}game.Workspace.Part.Position = Vector3.new(0, 50, 0) | {{CodeExample}}game.Workspace.Part.Position = Vector3.new(0, 50, 0) | ||
</pre> | |||
You should see that the brick moved up a good distance, you may need to move the camera to see it. What you just did is change where the brick is, by changing it's [[Position]]. As you should know from the [[basic scripting guide]], you changed the Position by using the equal sign. You set Part.Position to a new location by using the Vector3.new ''constructor.'' You ''constructed'' a new Vector3 using 3 different values. This told the Lua engine to set the brick's Position to 0, 50, 0, making the brick move to that position. | You should see that the brick moved up a good distance, you may need to move the camera to see it. What you just did is change where the brick is, by changing it's [[Position]]. As you should know from the [[basic scripting guide]], you changed the Position by using the equal sign. You set Part.Position to a new location by using the Vector3.new ''constructor.'' You ''constructed'' a new Vector3 using 3 different values. This told the Lua engine to set the brick's Position to 0, 50, 0, making the brick move to that position. | ||
Line 48: | Line 48: | ||
Moving things around with Vector3s comes with built-in collision detection. Lets say you have a huge brick, and you try to move another brick inside of it. Instead of appearing inside of the solid brick, the second brick will pop up on top of the large one right above where it's trying to get to. If you don't want this to happen, you can move objects around without this using [[CFrame]]s. | Moving things around with Vector3s comes with built-in collision detection. Lets say you have a huge brick, and you try to move another brick inside of it. Instead of appearing inside of the solid brick, the second brick will pop up on top of the large one right above where it's trying to get to. If you don't want this to happen, you can move objects around without this using [[CFrame]]s. | ||
|} | |} | ||
==[[Constructors]]== | ==[[Constructors]]== |
Revision as of 04:13, 30 July 2010
Vector3
A Vector3 is a number that holds three values inside it. This doesn't have to be a 3D position, it could be a size as well
Vector3 has three values, an X ordinate, Y ordinate and Z ordinate. They're kind of like those coordinates you use in school on graphs. I'm sure you've seen something like (1, 5) somewhere before. This means that on a graph you go to the right 1, and then up 5. That's because a coordinate uses an X and a Y value. It looks like this (x, y) Now you have a Vector2. We need a Vector3. So the difference is we add another value, a Z value. (x, y, z) That's really all there is to it. These numbers can be used for the Position of things, the Size of things, or anything else that needs 3 numbers to work. When people talk about the values inside a Vector3,
|
Using Vectors3s
Moving things around
Open up a new place with a part. Click here for a quick guide on how to set up a script testing Place
In the Command Line, type in this bit here and hit enter: Template:CodeExamplegame.Workspace.Part.Position = Vector3.new(0, 50, 0)
You should see that the brick moved up a good distance, you may need to move the camera to see it. What you just did is change where the brick is, by changing it's Position. As you should know from the basic scripting guide, you changed the Position by using the equal sign. You set Part.Position to a new location by using the Vector3.new constructor. You constructed a new Vector3 using 3 different values. This told the Lua engine to set the brick's Position to 0, 50, 0, making the brick move to that position.
Property you're changing | Set To | Value you want to set it to |
game.Workspace.Part.Position | = | Vector3.new(0, 50, 0) |
The Position of "Part" | Set to this |
Moving things around with Vector3s comes with built-in collision detection. Lets say you have a huge brick, and you try to move another brick inside of it. Instead of appearing inside of the solid brick, the second brick will pop up on top of the large one right above where it's trying to get to. If you don't want this to happen, you can move objects around without this using CFrames. |
Constructors
Constructor | Description |
---|---|
Vector3.new(x, y, z) | Creates a new Vector3 using ordinates x, y, z. |
Vector3.FromNormalId(Enum.NormalId normalId) | Creates a unit Vector3 in a particular facing direction. |
Vector3.FromAxis(Enum.Axis axis) | Creates a unit Vector3 for a particular Axis. |
Methods
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:Dot(Vector3) | Returns the vector dot product of the 2 vectors |
Vector3:Cross(Vector3) | Returns the vector cross product of the 2 vectors |
Properties
All of these properties are Read Only (you can't just set them Vector3.x = 5, it doesn't work) but you can create new
Property | Type | Description |
---|---|---|
Vector3.x | Number | The x-coordinate |
Vector3.y | Number | The y-coordinate |
Vector3.z | Number | The z-coordinate |
Vector3.unit | Vector3 | A normalized copy of the vector |
Vector3.magnitude | Number | The length of the vector |
Operators
Operator | Description |
---|---|
Vector3 + Vector3 | returns Vector3 translated (slid) by Vector3 |
Vector3 - Vector3 | returns Vector3 translated (slid) by -Vector3 (also gives relative position of 1 to the other) |
Number * Vector3 | returns Vector3 with each component multiplied by Number |
Vector3 * Number | returns Vector3 with each component multiplied by Number |
Number / Vector3 | returns Vector3 with Number divided by each component |
Vector3 / Number | returns Vector3 with each component divided by Number |
Vector3 * Vector3 | returns Vector3 with each component multiplied by corresponding component |
Vector3 / Vector3 | returns Vector3 with each component divided by corresponding component |
See CFrame for additional Vector3 operators.