In this recipe, we will create a very common gameplay mechanism: a moving platform. We will use a Rigid body for our character and an animated, kinematic Rigid body for the platform.
Before we start, you should have a scene with your character and a platform you want to animate. You can use the example project; go to the Chapter 02 Working with the animation view\Recipe 03 Animating objects world position - creating a moving platform
directory. There is a scene called Example.unity
there. If you open it, you will find a Sheep
character in the Hierarchy
. This is our character, using the Rigidbody
component and a Simple Move script to move. There is also a Moving Platform
game object in the Hierarchy
. This is the kinematic rigid body with a Platform
script attached to it. It also has an Animator component and an Animator Controller with just one animation in it. This animation makes the platform move.