Unity Development Part 12
- kw4u19
- May 25, 2021
- 5 min read
This development took place across week 11.
My aims for this session:
NEW Bridge puzzle
Patrolling Eagle - write its script
Windmill puzzle
NEW Bridge puzzle
Version one of the bridge puzzle did not function the way I wanted it to and had many problems to do with the colliders and the players movement over the bridge. My aim today is to re-build the bridge puzzle and make changes to the player so they can walk up and over small ledges to prevent them from getting stuck at on any colliders that I use.
Firstly, let's fix the colliders....
The two images below show how I have changed the colliders on the player. The box collider has been shrunk down as far as I could get it to shrink. Then I have given that box collider a radius of 0.6 so it has the same boundary that the box collider previously had, before shrinkage.
The colliders that I tried on the bridge before, being the polygon collider and the colliders I made from attaching loads of sprites with colliders on, have both been deleted gone. Then I activated the edge colliders that I originally put on the bridge.
With these changes the player is able to walk up and over the bridge completely seamlessly, no problems at all, and it looks entirely natural. Pleased!
And now, for how I made the new puzzle...
First, I removed the old script (BoulderOne) and any parts that were required for the old puzzle, such as the capsule collider on the player seen above in the images.
I then made a prefab in the scene called Boulder, adding a polygon collider and rigid body to it. Then separately made an invisible 2D sprite with a trigger box collider, and have placed that underneath the gap in the bridge. This has been called BoulderTrigger and given a tag of the same name.

Here is the script (titled BoulderVolume2):
In the start method we have called the Boulders rigid body.
The function is that the upon the boulders rigid body colliding with the boulder trigger beneath the bridge, all of constraints will be frozen, so it will stay in place exactly where and how it is.
If this function is to happen, we say that success is true.
In the IE numerator, I have said if success is false, then destroy the boulder. So if the player misses the bridge gap and the boulder does not collide with the trigger, it will be removed from the scene.
I have also put in a coroutine so there is a short delay before the boulder is destroyed. This looks better then it just disappearing.
As the boulder will not be destroyed for 3 seconds before after it has been thrown, the player could actually use it as a stepping stone at any point in the game. In the original project scope and initial idea development we were considering using a boulder that could be stepped on to traverse the environment but the idea was dropped later on, I guess the player could still use the boulder this way if they like.
Then in the player script:

When the player presses "e", spawn the boulder prefab and add some forces to the boulder, depending on the direction that the player is facing.
The values for the vector magnitude took some trial and error but now the boulder is thrown in a short curved trajectory and looks really good.
At the bottom of this page, there is a video demonstrating this boulder puzzle in action, as well as the cloud blowing, tree restoration and windmill puzzles.
Patrolling Eagle
The eagle's purpose is to fly high in the sky above the player, back and forth, while singing a tune. This tune is a clue for how to solve the final puzzle at the end of level, for which you must play a tune on some pan pipes to distract an eagle and clear it from blocking your path.

The image above shows where I have positioned the eagle and there is an invisible box collider to the left of it. The eagle is positioned between two of these box collider that will act as triggers to get the eagle to change direction and fly back the other way.
Here is the script I wrote to achieve this:

The eagles start position is facing and moving right.
In the start method, making moving right true.
In the update, make statements for either way the eagle will be facing, and give it a direction and speed to move in.
In a trigger enter method; On collision with the left sided collider, flip the eagle on the x-axis.
And make moving right true.
On collision with the right sided collider, flip the eagle on the x-axis again.
And make moving right false.
So to summarise, the eagle is made to change direction of motion and its sprite is flipped whenever it hits one of the colliders. I named the collider "Left" and "Right" so I would not get confused as to which is which and move them into the incorrect order. The eagle will bounce between these points for the length of the game.
Windmill Puzzle
The expectation for the windmill puzzle is that the player will simply use the gust ability to get its turbine to start spinning. I thought this interaction would have more meaning if perhaps the force of the turbine blows something out of the way could even transform the positions of the islands the players walks upon. But my target at the moment is to just get it to work the way my team have designed it to.
Here is what it looks like in the game:

The turbine and the windmill are separate objects. To begin the windmill puzzle, I put a trigger box collider on the windmill and increased its size until its boundary included that island on the left, in the image above.
When the player is inside the trigger box and presses the "r" key to use the ability, the animation for the turbine spinning is activated.
I wanted to simplify this puzzle by making the turbine object just spin, rather than have an animation play. But unfortunately the centre of the turbine was not the same as the centre point on the png and although I tried, I could not manage to move the centre point or re-crop the png properly so I just used the animation I had been given instead.
Here is what I needed to add into the script (PlayerMovementScript):

This piece of script is inside the start method, under the condition if player presses the "R" key.

If the player is facing right (towards the windmill) and is inside the trigger box (TouchingTurbine), then set the bool "isSpinning", on the turbines animator, to true. So therefore when the player uses the gust ability in this location, the turbine on the windmill will spin.
Inside these voids are scripts to tell the manager when the player is "TouchingTurbine" which just means, when the player is inside the trigger collider of the windmill.
If set to true, the puzzle can take place.
A clip showing this puzzle in action is posted below.
Reflection
I think this week has been really productive so far and I'm happy with the progress that I am making. I am especially happy that i was able to get the boulder puzzle to function a lot better and it was really rewarding to finally have it looking so great and as we designed it to look too.
This video below shows the progress of the puzzles so far. Four out of the five puzzles have been created, I just need to go back and make sure that animation for the tree restoration puzzle is working properly because it did not play when I filmed this clip.
Next Steps
The lanterns have already been places where they need to be across the level. I need to put into the code a function to make them turn on once the respective challenge for each one has been completed.
Implement UI prompts, made for tutorial purposes, and the Start screen.
Make final changes to the game scenery, fixed position for all assets and build up background detail, so the Molly can work on the lighting without me then making changes afterwards and messing that up.
Make the panpipe puzzle functional.
Comments