3D Coordinates and Positions
CreatiCode last edited by creaticodeta2-mail
By default, all objects we add to the 3D world are positioned at the center of the world - the “origin” point. To move an object to a different position, we need to use “coordinates”.
In 1-dimensional worlds, everything is positioned along a very long arrow - the X-Axis. So if a point is at x of 50, we go 50 steps from the origin of the arrow along its direction to find that point. If a point is at x of -30, we start from the origin and go against the x-direction for 30 steps to find that point.
In 2-dimensional worlds, we use 2 coordinate numbers to represent the position of a point. For example, if a point is at x position of 50 and y position of -30, we find those 2 points in the X and Y directions, then find the point that is aligned to both of them.
In 3-dimensional worlds, we use 3 coordinate numbers. For example, if a point is at x of 50, y of 30, and z of 40, we first find those 3 points along each direction arrow, then find the point that is aligned to all 3 of them:
The good news is that these motion blocks work in 3D projects as well:
For example, suppose we have added a yellow box to an empty scene. Its position will be at the origin. Note that this means the center point of the box, as indicated by the red dot, is at x of 0, y of 0, and z of 0.
When we set the x position of the box to 100, its center point will be shifted along the X direction by 100 steps instantly. The other blocks work in a similar way as in 2D projects.
There is also a new block for moving to a 3D position:
Seconds: When this input is more than 0, the object will glide towards the 3D position over that number of seconds as an animation.
Blocking Type: If “Blocking”, then the program will keep running this block until it completes; if “Non-Blocking”, then the program will continue to run the next block below this block right away. This is useful when you want to keep moving an object in a long animation, but also run the code below right away.
Here is a simple example of moving a box through a 3-second animation.
Sometimes you know where you want to move an object to, but it is not easy to figure out the exact position numbers to use. You can use the position gizmo to help you.
As shown, you can turn on or off the position gizmo by clicking the small button with 4 arrows on it. When the tool is enabled, you can click on the object you want to move, and you should see 3 small arrows centered at that object. When your pointer hovers over an arrow, it will be highlighted in yellow, and then you can drag it to move the object.
As you drag an object, observe that the x/y/z position values in the sprite pane will change accordingly. In addition, the position values in the motion blocks in the flyout will also change, so you can readily use them when you are done with dragging the object.
Very often, we have more than one object in a scene. When we use the “move to” block, the object that was added right before this block would be moved.
For example, in this program, the first move-to block would move the red box to X of 200, since that red box is the last object added to the scene before the first move-to block. However, the second move-to block would move the blue box instead.
This is what we get as a result: