My journey becoming a Unity game developer: 2.5D Infinite Runner-URP and Player’s 3D model added
Objective: Using the Universal Render Pipeline on the imported game assets. Also, adding a 3D model to the Player object and adjusting its movement in the game.
To install the URP package, go to Window->Package Manager. Change the` Packages list selection to Unity Registry, find Universal RP, and download the URP package.
We installed some sci-fi game objects for this scene, but the assets didn’t render properly in Unity. They came in magenta, meaning the materials with their textures attached to them aren’t showing up on the assets. One way we can fix the graphics is to use the Universal Render Pipeline (URP).
The URP Asset controls the global rendering and quality settings of our project, and creates a rendering pipeline instance. The rendering pipeline instance contains intermediate resources and the render pipeline implementation according to the Unity Manual.
In the Project window, create a folder name Settings inside the Assets folder. Right-click on the Settings folder, select Create->Rendering->Universal Render Pipeline->Pipeline Asset as this will create the URP Asset and URP Asset Renderer files.
Go to Edit->Project Settings->Graphics->Scriptable Render Pipeline Settings. Click on the circle icon and select the URP Asset as this will render the assets from magenta to their materials and textures the artist used for each asset.
Now a little problem arose with importing these assets in that they are rotated in a different direction. Looking at our original code, the player is moving forward along the X-axis through the horizontalInput variable inside of the direction variable. Also, we can either comment out or remove the verticalInput variable as the Player will not be moving from side to side.
If we look at the Player moving along the X-axis, we see the Player moving side to side instead of forward and backward. The Z-axis now represents the forward and backward directions for the Player just by looking at the Scene Gizmo that appears in the upper-right corner of the Scene view which displays the Scene view Camera’s current orientation. We could have tried to rotate the Game Assets and Main Camera, but it was easier to just change the code in this situation.
Change the horizontalInput to the Z-axis spot in the direction variable.
The Player is moving back and forth now, so we can now proceed in playing the game as normal.
Next, we’re going to add a 3D character model to the Player object. Drag your 3D character model onto the Player object to make it a child of the Player. On the Player object, we can remove the Mesh Renderer which will remove the Capsule being rendered onscreen. Also, remove the Capsule Collider as we will receive a new collider with the Character Controller.
If the model’s physical stature comes in inaccurate for the game like ours did, just head over to the Transform component and change the Scale to 2 meters for the X, Y, and Z-axis. This will scale the model to a normal human physical appearance used in video games.
Adjust the Collider that comes with the Character Controller around the Player using its Height and Radius located in the Character Controller component.
Using the code prototype we created with some minor adjustments, we can see the Player moving forward and backwards. Also, the Jump code is still working as well.
Next time we will add an Idle, Running, and Running Jump animations to the Player which will represent a more realistic player movement.