上QQ阅读APP看书,第一时间看更新
Adding Edge Collision and Gravity behaviors to a ball
Combining simulation behaviors can create some complex animation. Let's take a look at how we can make a ball bounce around our Canvas.
How to do it...
- Double-click to open the
03_05
project. - Press the Space bar to start the playback. This project consists of a 3D ball being tossed across the screen using the Throw behavior. Click on the disclosure triangle for the group to reveal its content. You can see the behavior along with the filters used to colorize the object. Let's add a little gravity to the ball so that it falls down.
- Go to the gear icon just under the Canvas and choose Gravity from under Simulations. The Throw behavior is affected by gravity and the ball now falls down.
- Press the F7 key to reveal the HUD. Increase the Acceleration to a value of 100. Notice how the ball falls down quicker as shown in the following screenshot:
- Press the D key a few times to cycle to the Throw behavior in the HUD and drag the arrow to the right-hand side to increase the throw velocity. Since the ball is being thrown more aggressively, gravity has a different effect. Experiment with different values for the Throw Velocity and Gravity Acceleration. Press the F2 key to go to the Behaviors tab of the Inspector.
- In the Behaviors tab, change the value of Gravity Acceleration to 2000 and under Throw Change, the Throw Velocity on X and Y to 1000.
- Select the 3D ball in the Layers tab. Go to the gear icon just under the Canvas and choose Edge Collision from under Simulations. Use the following screenshot for reference:
- By default, the edges are set to the width of your project. In this case, it's 1920 by 1080. Play back your animation by pressing the Space bar and notice that as soon as the ball comes close to the edge, it will bounce away from it.
- In the HUD, bring down the Bounce Strength to 50 and see how the ball slowly loses its bounce each time it hits the edges. Bring the Bounce Value up to 100.
- If the ball appears to not quite hit the edge, try increasing the height and width slightly. For Width, I used 2020 and for Height, 1180. Use the following screenshot for reference:
- As a final step, select the 3D ball in the Layers tab. Go to the gear icon just under the Canvas and navigate to Simulations | Align to Motion (Simulations). Notice how the ball rotates when it moves. Decrease the Spring Tension in the HUD to 50. Try playing around with the other behavior settings to see the different results you can get.
See also
- The Adding an Attractor and Attracted To behavior recipe
- The Creating Random Motion using the Randomize behavior recipe
- The Stop, Wriggle, Rate, and Quantize recipe
- The Using the Link behavior recipe