Posts

Showing posts from May 4, 2018

Gamespace: Restarting Game

Image
I have set the Gamespace to restart whenever a player falls off the edge of the world or the health bar points have decreased to zero due to the rain cloud enemies. I found that if I put a cube underneath my landscape and the player collided with it (due to falling off) I could set the Gamespace to restart which means that the player does not need to manually restart the game by reloading the exe file. I made this cube invisible by removing the mesh renderer component as the Gamespace would look unprofessional and messy if the cube could be seen. A tag named 'Respawn' is attached to the cube so that it can be identified in the script. Restarting the Game by falling using collisions This is the inspector for the restart cube, a box collider has been added to the object so that the script can detect when the player has fallen off of the landscape. Restart Cube Inspector The 'Respawn' script detects when a collision has occurred with the invisible box...

Gamespace: Health Bar

Image
I decided to add a health bar so that when the player collides with an enemy, they lose health. When the health point value is equal to zero, the Gamespace restarts. Health Bar Game View The health bar gameObject held the foreground and background for the health bar. Health Bar Inspector This is the inspector for the background used in the health bar.  The background is only shown when the player loses health as the foreground bar decreases in length. The colour has been changed to a dark grey to fit the sky theme. Background Bar Inspector This is the inspector for the foreground bar used in the health bar. This bar decreased in length when the player loses health. The X Pivot has been set to zero so that when the player loses health, the bar only decreases in length from right to left. When the bar does not exist anymore, the player's health is at zero and the Gamespace restarts. Foreground Bar Inspector The 'HealthBar' scrip...

Gamespace: Enemies

Image
I wanted to create an enemy that when the player collides with the object points are deducted from the health bar. I also wanted my enemy to fit with the theme and therefore made it look like a raincloud. Raincloud enemy with added box collider Raincloud enemy deducting points from the health bar This is the inspector for the raincloud enemy.  The 'Enemy' script is attached and a box collider component is added so that when the player collides with the enemy the script understands that a collision has occurred. Cloud Enemy Inspector The Enemy script works by using an 'OnTriggerEnter' function. Therefore, when the player collides with the box collider that encapsulates the rain and rain cloud this function is called. The variable 'healthBar' is received.  If the value assigned to the health bar is not equal to nothing, then the health bar takes 10 damage when the player collides with a raincloud. Enemy Script To make ...

Gamespace: Moving End Platform (Panel Animation)

Image
Once I had got the platform to move back and forward, I decided that I wanted the panel to lift up depending on whether the player was close to the platform otherwise the panel would stay downwards. Panel staying down This is the inspector for the moving end platform. The 'Panel Open for Player' and 'Panel Closed for Player' scripts are attached to this object. A sphere collider has also been added so that when the player collides with the collider this triggers the panel to lift. Moving End Platform Inspector Sphere collider where the panel is lifted The 'PanelClosedForPlayer' plays the closed animation when the player has not collided with the collider. If the 'IsOpen' parameter on the animator is false then the panel will close otherwise the panel will be open. Panel Closed For Player Script The 'PanelOpenForPlayer' script uses the 'OnTriggerEnter' function which is triggered when the player...

Gamespace: Moving End Platform (Movement)

Image
I wanted my last platform to move and say the word 'FINISH' so that the player knows where the end of the landscape is. Platform Moving Away Platform Moving Closer This was the inspector for my moving end platform. The Script 'Moving End Platform' has been attached to it. Moving End Platform Inspector The Vector 3 variable 'initialPosition' is set to private so that it cannot be changed in the inspector. The 'initialPosition' variable is assigned to the object's location using 'transform.Position' in the Start() function. In the Update() function, the position of the platform is set using the initial position of the platform (using the variable 'initialPosition') plus the new 3D vector where the X-axis is equal to zero, the Y-axis is equal to zero and the Y-axis is equal to a Sin wave multiplied by three to make the wave bigger. This moves the platform continuously on the Z-axis. Moving E...

Gamespace: Collectable Item Coded Animation

Image
After successfully picking up one ball, I duplicated this object and placed them all over the landscape. Items spread across landscape To make the object more interesting I wanted to add movement and rotation to the object as all items were completely still. Item I attached two scripts to the Collectable Item inspector 'Idle Move' and 'Constant Rotation' where the amplitude was set to 0.15, the frequency was set to 2 and the speed of rotation was set to 90. Collectable Item Inspector The 'Idle move' script has two float variables 'amplitude' (how far up the item goes when moving) and the 'frequency' declared as public meaning that they can be edited in the inspector. The Vector3 variable 'initialPosition' is set as private meaning that it cannot be edited outside of the script. The initial position of the item is assigned in the 'Start' function. The value assigned to the 'initialPosition' var...

Gamespace: PickUp Collectable Items

Image
I created a way for my items (mini balls) to be picked up by my player. I also added a particle system so that when the balls were picked up, they almost 'exploded' making the Gamespace more interesting. My particle system before changing the values My particle system after changing the values This was the first 'PickUp' script that was used so that the player could collect the items. The ParticleSystem named 'particles', the Renderer named 'collectableItem' and the Vector3 named 'ball' were all made public so that they could be edited in the inspector. The function 'OnTriggerEnter' was used so that if something (the player) collided with the item, this function is triggered. The if statement states that if an object has the tag 'Player' and has collided with the item, the particle system will play (Particles.Play()), the components collider has been disenabled so that it cannot be picked up again, the ...

Gamespace: Moving Platform

Image
Moreover, I wanted to include a moving platform to make my Gamespace more exciting and add difficulty. This functionality was added before I re-coloured the assets. Platform moving up Platform moving down The 'Moving Platform' script is attached to the moving platform in the inspector. Moving platform Inspector The 'MovingPlatform' script declared the Vector3 variable 'initialPosition' as private meaning that the value does not need to be changed outside of the script in the inspector. My initial position which can be taken from the command 'transform.position' is stored in the 'initialPosition' variable. The transform.postion is set every frame and equals wherever I was located initially (stored in initialPosition) with the addition of an offset where a new 3D vector is created. The X-axis is equal to zero, the Y-axis is equal to a Sin wave that alternates multiplied by five to give a larger wave meaning that th...

Gamespace: Windmill

Image
I created the functionality for the windmill before re-colouring the assets. I added a rotating windmill to add more obstacles to the gamespace making collecting the items more difficult for the player. Windmill Game View The inspector for one of the windmill arms shows that the 'RotatingWindmill' script is attached to it and the speed of the windmill arm is going at 0.44. Additionally, the other windmill arm has this script attached to it in the inspector and is also travelling at a speed of 0.44. Windmill Arm Inspector The 'RotatingWindmill' script allows the windmill arms to rotate around a point at a speed per second. The float variable 'speed' has been made public meaning that this value is editable outside of the code. The rotation command is transform.Rotate. A new 3D vector has been created to tell the windmill arm to rotate at a specified speed on the X-axis and nothing on the Y or Z-axis as these values have been set to zero. ...