My journey becoming a Unity game developer: 2.5D Infinite Runner-Updating camera, moving platform, crouch to standing idle animation
Objective: Have the Main Camera follow the Player character using Cinemachine. Also, add a Crouch to Stand animation to blend in between the Climb Up and Standing Idle to make the Player look more realistic standing up. Finally, adjust the Moving Platform prototype to show a platform that matches the scene while still being able to carry the Player on it.
We want the Main Camera to follow the Player as they move through the game using Cinemachine. Make sure to install Cinemachine from the Package Manager if you haven’t (Window->Package Manager). Select from the Menu, Cinemachine->Create Virtual Camera to create the virtual camera that will follow the Player.
In the CineMachine Virtual Camera component, drag the Player character object into the Follow setting to have the virtual camera follow the Player at all times. Set the Aim setting to Do Nothing as Aim is associated with the Look At setting, while the Body setting is associated with the Follow setting.
For the Body setting, set it to Transposer which will move the camera in a fixed relationship to the Follow target. With the Binding Mode we started out using World Space which the Follow Offset is interpreted in world space relative to the Follow target’s origin, plus the camera will not change position when the target rotates.
Also, we used the X and Y Damping by setting it to 3 which will set how responsive the camera tries to maintain the offset in the X-axis and Y-axis. Small numbers make the camera more responsive, while larger numbers make the camera respond more slowly. Therefore, by setting it to 3 we want the camera to not snap into position right away, but instead glide into position after a second or two.
Then we changed the Binding Mode to Lock to Target on Assign which makes the Virtual Camera use the Follow target’s local frame at the moment when the target is assigned. Also, the offset remains constant in world space, and the camera does not rotate along with the target. Play around with these settings to find which one looks best to you.
We wanted to improve the Player’s animation when climbing up off the ledge to their Standing Idle animation by adding a new Crouch to Standing animation from Mixamo. After downloading, placing the animation into the FBX folder in the Assets folder, and duplicating the animation then placing the duplicate animation into the Animations folder, drag the animation into the Animator. Place the Crouch to Standing animation between the Climb Up and Standing Idle animations. Click on the duplicate Crouch to Standing animation, turn off the Loop Time and Bake into Pose the Root Transform Positions.
Reset the transitions to go from Climb Up->Crouch to Standing->Standing Idle. The Climb Up->Crouch to Standing, leave Has Exit Time turned on, Exit Time and Transition Duration set it to zero. With Crouch to Standing->Standing Idle, set it the same as Climb Up->Crouch to Standing transition. You may have to adjust the transition animations between the 2 to make the Player animation look smoother.
As we watch the Player climb up animation, we can see the Player get up from their crouch stance to a standing position with a more realistic appearance. Also, the virtual camera is following the Player character as they move through the game.
Quickly, we are going to implement our Moving Platform prototype into the game as well. Drag the Moving Platform prefab into the Scene View where we can see it clearly. Under the child Moving Platform game object, go to the Mesh Filter and change the mesh from Cube to the mesh that will represent your moving platform, in this case was Plane_002. The Mesh Renderer was changed to the floor material to render the image of the floor. Drag the Player game object into the Player slot under the Moving Platform script component.
Both Box Colliders were Reset from the hamburger menu to fit the floor. With the 2nd Box Collider, we need to adjust its Y-axis Offset to raise the collider above the floor which will keep the Player on the platform when it’s moving. Also, turn on the Is Trigger for this Box Collider to allow the Player to stand inside of it while on the platform.
With the Rigidbody component go to Constraints which will stop the Rigidbody from moving in the world along X, Y and Z axes selectively. Turn on the Freeze Rotation along all 3 axis so the platform isn’t allowed to rotate while moving. With the Freeze Position, we will turn on the X and Y-axis to freeze it while it moves along the Z-axis. The other platform which is moving along the Y-axis, turn on the X and Z axis to freeze their positions.
Set the target positions A and B of the Moving Platforms to the positions where you want the platforms to move between.
Player is now being moved from one location to another on the moving platforms.