top of page

Unity Development Part 11

  • kw4u19
  • May 24, 2021
  • 3 min read

Updated: May 25, 2021

This development took place across week 11.


My aims for this part:

  • Tree restoration puzzle

There was going to be more planned initially but this took me so so long to do.


Tree restoration puzzle


Expectation: The player comes across a dead tree and remembers that their objective is to restore beauty and light up the lanterns across the level. They need to use the gust ability to apply a force to some rain clouds that will move over the dying tree and restore its health.


The scene:


I began by moving the island on the left to the higher position that they are at now. So the player will be standing on top of that first platform of the highest elevation when they interact with the puzzle.


On the Raincloud, I added a collider with a trigger and resized it so it covers the first platform so the player will be able to walk into it. I then added on a rigid body and froze rotation on the z and y axis as I only want the rain cloud to move horizontally. Next I gave it a tag "RainCloud".


I have added changes, for this puzzle to work, in the player movement script. Here are steps bullet pointed below...



1. To get the rain cloud to move, I first needed to set up some variables:


bool TouchingRainCloud = false


bool RainCloudMoving


GameObject RainCloud



2. Then in the update method:


The first if statement is checking if the player is pressing "R"


And then within in it, if the player is touching the rain cloud (is inside its trigger box), then "RaindCloudMoving" becomes true.


Then in the second if statement, the instructions on where to transform it is written, moving the rain cloud to the right by 4 "spaces".



3. The circumstances for when the player is or is not inside the trigger box:



First void statement: When the player is inside the rain clouds trigger box, touching the rain cloud is true and therefore when they press "R", the rain cloud will move to its new position as expressed in the update method.


Second void statement: When the player is not inside the rain clouds trigger box, touching the rain cloud is therefore false and nothing will happen to it when the player presses "R".



Now onto the method to get the tree to be restored, playing the blossoming animation, after rain cloud movement takes place...

1. Firstly in at the top of the player script again:


Animator TreeRevival;


bool TouchingDeadBlossom = false;


GameObject DeadBlossom;


2. Within the update method, we add this piece of script:


This is just saying that we are going to start a method called Blossom when our statement TouchingDeadBlossom is set to true



3. Within in the trigger enter function:

When the game object with the tag DeadBlossom is triggered, get its animator and set TouchingDeadBlossom to true.







4. Within the trigger exit function:

When the game object with the tag Deadblossom is not triggered, TouchingDeadBlossom is false.









5. Now setting up the coroutine we mentioned in the update:

The blossom method is started here. First there is a delay of 4 seconds and then the animation with the trigger "isBlossoming" in the DeadBlossoms animator is played.


In summary; The player enters a trigger box attached to the rain clouds, and by pressing the "e" key to use the gust ability, they trigger the transformation of the cloud position to the point above the dying tree. This in turn will cause the tree restoration animation to play after a delay of four seconds.



Reflection


This was the most difficult task I've probably ever had to do and it took me an awful amount of time across two days. It was incredibly hard to understand what parts of the script to go where and how to trigger the restoration animation to play after the tree had stopped moving. I am also not sure how well I explained the process of doing this but I'm just pleased that it does work!


Commentaires


bottom of page