Unity Development Surgery 29/04
- kw4u19
- May 24, 2021
- 3 min read
This development session took place during week 9.
My aims for this session:
Create player death
How to implement check points
Make the boulder-bridge puzzle functional
Player Death
The expectation: when the player falls from a floating island and descends down below, they should re-spawn at the beginning of the scene.
To achieve this we first started by creating a box sprite that spans the entire length of the game and named it "Death Box". Then added a box collider to it, with the trigger box selected, so when the player falls and collides with this box, the scene will reset and then so will their position.
Here is the script, titled "Reset", that was then applied to the Death box:

It is a relatively simple piece of script that first references a public int, the scene number (the beginning of the game being scene 0). Then we have a public Vector 3 (representing a displacement, in direction and magnitude, in 3D space) called "respawn".
The method states that on the event of a collision with death box and if the game object that collides with it is the player, that game object will its position changed to position of the re-spawn.
In the inspector, under the script component of the death box, the scene number and re-spawn position can be set to any value for this to work.
For checkpoints:
I need to make a new death box for each "scene", then apply this same script and change the scene number and new re-spawn position respectively.
The boulder-bridge puzzle
Expectation: The player throws the boulder and then it fills the gap in the bridge so the player is then able to cross it safely, not falling to their deaths.
First we made another square game object and we will call that the boulder. This had a rigid body and box collider attached to it. This was placed at the beginning of the bridge.
Next another square game object was made and we will call that the bridge gap. This was placed in the gap of the bridge, meeting the steps on each side. Again, a rigid body and box collider was attached to this so it was able to be walked over. The gravity was set to 0 so it didn't just descend down forever.
Then another collider was placed on the player, and moved so it was completely in front of them and the purpose of this is too detect the boulder asset at the beginning of the bridge and this will trigger the boulder to be able to be moved into the gap on the bridge. The visuals achievable once the details had been flourished.
For the scripts:

First we created a new script, shown above, so when the bridge collider is triggered, the sprite renderer and the box collider on the bridge gap are enabled, so the gap fills and the player can walk over it.
Then in the player movement script, shown below we had quite a few additions to make. I have cut out the unnecessary details for clarity.

First a private collider is establish "ee" and this is put on the boulder that recognises when the player is close enough to trigger the puzzle event. We have referenced this boulder object "PlayerBoulder" and its rigid body.
In the start method we tell the controller to fins the collider. And then in the update we write that we the player presses e, the collider "ee" is disabled and the player can move past and onto the bridge, where the gap has been filled so they cross to the other side safely.
This process was honestly quite confusing for me and even after analysing the script and going over again what was done, I still don't really understand. But as of now, the bridge puzzle is functional, it just needs the flourishing details such as replacing the gap sprite render with an actual boulder and making sure a boulder throw animation plays when the player presses "e" to interact with the puzzle.
The colliders on the bridge still don't work very well so further work needs to be done to refine them so the player is able to pass over this puzzle smoothly. I am happy with the progress made this session but I do think there might be a more seamless method to get this interaction to work but that's all for today!
Comments