Homework

As in every chapter, here are some exercises that you can use to practice your skills:

  1. The forgotten rigidbody: Sometimes components in the Inspector could be forgotten. However, we can facilitate the process by creating warnings in the code. For both our Panda and the sprinkles, create within their scripts a check, when the game object is initialized, to add a Rigidbody2D component, if missing, and set it to be Kinematic. Additionally, you can print a warning message (See Chapter 8, What Is beyond the Cake?, for more about debugging messages).
  2. Passion for acceleration: In the chapter, we saw how we could implement motion equations for our Kinematic rigidbodies. In particular, the chapter shown an implementation of the velocity equation. Now, try to implement the acceleration equation for a Kinematic rigidbody.
  3. Joint Master: For each one of the joints that Unity offers, think about a possible usage and example (possibly different from the ones already presented in the chapter). Then, sketch the physical system on paper, and determine which are the rigidbodies and where the anchor points are. Finally, reproduce what you have imagined within Unity, and tweak all the settings until it works as you have decided.
  4. Effector Master: For each one of the effectors that Unity offers, think about a possible usage and example (possibly different from the ones already presented in the chapter). Then, sketch how the effector should work on paper, and determine how the different rigidbodies would interact with it. Finally, reproduce what you have imagined within Unity, and tweak all the settings until it works as you have decided.
  5. A less dauntless Panda (Part III): If you also completed the second part of this exercise back in Chapter 4No Longer Alone - Sweet-Toothed Pandas Strike, some pandas will be stunned, others not, depending on the Boolean value. Instead of exposing this Boolean within the Inspector, add this property to the Projectile class, so that if the Panda is stunned or not depends on which kind of projectile the Panda was hit with (we will see this later in Chapter 6Through a Sea of Sprinkles – Navigation in Artificial Intelligence).
  6. A less dauntless Panda (Part IV): After you have done part three of this exercise, if the poor panda is under attack with too many sprinkles, it might not move anymore because it is always in a stunned state. As a result, it won't able to avoid the sprinkles either. So as to avoid this, we need to modify the Panda script such that if another sprinkle hits the Panda while it is stunned, it detracts the health from the Panda; but doesn't trigger from the beginning the hit animation and/or the stun period.
  7. A less dauntless Panda (Part V): Now that you have also completed the third part of this exercise, let's improve the whole system of stunning a Panda. Add to each projectile, a variable that indicates the chance of this projectile to stunning a Panda. Finally, trigger the stunning phase of the Panda probabilistically based on the previous variable.

    Finally, if you are into challenges, here is one for you:

  8. The frozen conveyor belt (Part I): Imagine a conveyor belt that is made of a big piece of ice and scrolls quite fast. Think and describe what would happen when a box is dropped onto it. Keep in mind that the friction on the ice is really low, and that there is inertia to consider. What if, instead of a box, there was a sphere? The solution is available at the end of the book.
  9. The frozen conveyor belt (Part II): Once you have done Part I, reproduce the frozen conveyor belt within the Physics engine of Unity, and try it out with boxes and spheres.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.46.229