O'Reilly logo

Practical Game Design with Unity and Playmaker by Sergey Mohov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Interaction between game objects

Now that the mallet moves, we are going to make it interact with a puck. When the mallet touches the puck, we are going to apply a force to it in the opposite direction.

You can click the Play button in the toolbar and see how the mallet moves based on the mouse position. You will notice that it collides with the walls, follows the mouse cursor smoothly, and changes its movement speed based on how fast and far you move your mouse.

  1. Create another cylinder called Puck and place it in (-3, 0.85, 0). Set its scale to (1, 0.7, 1).
  2. Add a Rigidbody component to it (Component | Physics | Rigidbody). Set the Mass property to 0.1, uncheck Use Gravity, open the Constraints section, and check Freeze Position Y and Freeze Rotation ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required