top of page

CG Lab 1

  • yasobel
  • 20 sept. 2020
  • 2 min de lecture

Dernière mise à jour : 1 nov. 2020

3D Platformer with Unity


After getting familiar with Unity's main functions, it was time to start creating a minigame from scratch. As opposed to the Karting game where practically every object, material and script were ready to use. We had to learn how to do everything on our own.

During our first initiation to Unity, we went for a simplified 3D platformer game.

I started by creating 3D objects to use as a platform for our player. By adding materiel options, I was able to modify their color, texture etc..









After creating a small platform, I added a bouncing sphere by using the option Physical Material as well as a gliding cylinder.

To avoid that the sphere falls off the platform when colliding with the player, I froze its X and Z coordinates.

As for the player, I used a capsule for the body and added a sphere as child to attach a head to the body. And finally, I created and empty object named target that I used later on for the camera.

In fact, I put the camera as child for the target so that it would follow the player around the platform.

A script was added to allow our player to move around and jump.


To practice using trigger colliders, I added a quad representing the end of the platform. When the player collides with it, its color changes from red to green to indicate that the player has won the game.








The script for the trigger collider :

To avoid having to manually restart the game every time the player falls, I implemented a death wall.

First of all, I started by adding a terrain underneath the platform.

Then I created an empty object named teleportTarget that is placed at the beginning of the platform.

Next, I implemented a script that teleports the player to the same coordinates as the teleportTarget whenever he collides with the terrain.
















However I have encountered some problems with the death wall :

Sometimes the screen starts glitching when the player dies and respawns at the beginning of the platform.

And I still have to reset the gliding cylinder’s position every time the player respawns.


-> To solve the glitching problem, I changed the player object from capsule to cylinder because the flat surface of the cylinder works better.


Tips :

To have access to a private variable on unity we use the [SerializeField] option in the script.


To activate a trigger collider we need to have a rigidbody component.


Forces don't apply to a kinematic rigidbody, only friction does.


We can't enter the "play mode" unless the tool handle is on global.


The teleport target should be a little bit above the platform to avoid a collision with a player thus to avoid bugs and glitches.


Each class inherits from Monobehaviour, this allows us to put the script on an object in unity.

Posts récents

Voir tout

Comments


bottom of page