Point Object Towards a Position
-
Introduction
When you add a new object (such as an airplane) to a 3D scene, its default facing direction is the positive Y direction. You can make it point in a different direction by specifying a target point with the following block:
This block takes 5 input parameters:- X/Y/Z Positions: These are the positions of the target point.
- Period: This is how long it will take the object to rotate in that new direction. If it is 0, then the object will turn immediately; otherwise, it will rotate gradually toward the new direction through animation.
- Blocking: When the “Period” is not 0 seconds, this parameter controls whether this block will block execution of the current block stack. If “Blocking”, then the program will not continue until the object finishes the rotation; If “Non-Blocking”, then the program will continue to the next block while keeping the object running its rotation animation.
Example
In this example program, we add an airplane model first, then make it point to the target point at x = 100, y = 100, z = 20, through an animation of 2 seconds long.
Note that the target position only affects the rotation direction relative to the position of the object. In this case, if we used (10, 10, 2), we would get the same result, since the object is at the position of (0, 0, 0).
Parenting + Point to Position (Advanced)
Sometimes when you may not get the desired result when you use the “point to position” block, since there can be many ways to rotate the object.
For example, when we rotate the airplane to point at the position of (100, 100, 100), the airplane’s body would “roll” around itself, so the left wing will tilt higher than the right wing:
To have more control over how the object’s body is rotated, you can use a parent object to do some or all of the rotation.For example, you can use a transformer object “t” as the parent of the airplane. Then you use the “point to position” block to rotate the airplane to point upwards, and rotate the parent object around the Z-axis to the right. This way the 2 wings will be at the same level. You can make the first animation non-blocking so the 2 animations run at the same time:
-