Game Development Reference
In-Depth Information
How it works...
The for loop creates eight waypoints along a circle at 45 degrees distance from each oth-
er. However, to make a complete circle the first and last waypoints need to be connected or
the path will stop at the final one. This is why setCycle(true) must be set. This is
treated as the ninth waypoint at the same position as the first.
MotionEvent's initialDuration is the time it should take to complete the path. The
speed defines the factor at which the initialDuration should be completed. So, set-
ting the speed to 2f will halve the actual time it takes for the object to complete its move-
ment. The loopMode , not surprisingly, defines whether the object should stop once it has
completed the path, or continue. There's also an option to make it go back the same path
again with LoopMode.Cycle . This is not related to MotionPath's setCycle method.
While this recipe doesn't explore the option, it's possible to have the spatial in Mo-
tionPath perform various types of rotation. By default, no rotation will be applied. By
calling setDirectionType it is possible to, for example, let the object follow the path's
rotation (face the direction of the path) or rotate by a fixed amount or always face a certain
point. Some of the direction types require a rotation to be supplied with the setRota-
tion method.
Search WWH ::




Custom Search