Unity: Ruby's Adventure Lesson2
Following on from our last unity lesson we started of by making our games a bit more realistic. We did so by making it so when Ruby walks around the decorations will be infront or behind them depending on where on the screen Ruby is. This was done through Edit>:Project Settings>Graphics>Transparency Sort (Custom Axis: X0 Y1 Z0). This would make unity render things depending on their Y axis rather than the Z axis. We then had to edit the pivot spot of sprites (In the project folder) so that they were at the bottom. (The pivot spot is the point which would determine the Y axis of the sprite) and then in the sprite in the hierarchy we would need to change the sprite sort to Pivot so that the pivot point is used when ordering sprites. Now decorations would appear infront or behind Ruby depending on the Y axis, which looks more realistic.
We then learnt about prefabs, which are sort of like master sprites which will change all other of the same sprite when changes are made to the prefab. This is helpful for if you accidentally delete something or if you want to make changes to multiple of the same sprite. You can make a Prefab by making a 'Prefab' folder in assets and dragging a sprite into it. The sprite name should then turn blue in the hierarchy. If you make an edit to a non Prefab sprite (Including Prefabs that have been added to the scene) the changes will only be made to that sprite, however there is an option to override changes which will update the prefab and all other of the same sprite which are in the scene. You can double click a prefab to edit it, this opens a window which shows only the prefab. I found this helpful for when editing colliders for multiple of the same sprites.
We then added Colliders so that ruby would not walk through things. We used Box Colliders (2D) rather than Polygon Colliders since for in the future when we make bigger games it is better to use Box Colliders since they have less points and therefore are better for performance. However since when you apply Box Colliders they cover the whole sprite and some of the area around the sprite, you need to make the Box smaller. For Ruby we made the box so it just covered the legs. We also added a Rigid Body 2D to Ruby so that she would actually collide with the objects, however we needed to change the gravity to 0 (So Ruby does not fall) and Constraints Z.
We then edited the Ruby Controller script so that the Rigid Body would control Ruby's movement since before editing the script Ruby was jittery when walking into colliders since the script was trying to move the position out of the collider but we were trying to move Ruby into the collider. Make sure that these changes were made to the Prefab Ruby or use the override to make sure that if you add another Ruby or lose the current one , the Prefab will have the same properties/scripts so you can just add another into the scene.
We then added a collider to the water tiles so that Ruby would not be able to walk on water. We did so by adding a Tile Map Collider 2D to the tilemap and then within the tiles folder we selected all non-water tiles and changed the collider type to none. We could then see greenboxes around all the water tiles. We also added a Composite Collider 2D, which would combine the collide boxes which are next to eachother. Changed the Rigid Body to Static and Ticked 'Used by composite in tilemap collide'.
We then had a go at making out own sprite in Photoshop and then adding it to the game, this is what I made. (We referenced the size of one of the assets from the game to get an idea for the scale 131x131 pixels and we also made sure the background was set to transparent.) I also added a scaled down tree shadow under this sprite so that the shadow matched the other decorations.
After this we added a Health function to Ruby so that we could add in objects which would add or take away health. We could then add a Collectable health object and add a script to it so that ruby would gain health when walking over the object then the object would be destroyed after. To make this script work we had to edit the settings of the collider in the collectable so that it is a trigger. For this script we deleted the Updtae and start functions and instead used 'Get' and 'If' statements.
Finally I added a damage area sprite to the game and had a go at editing the health script so that it would damage Ruby instead. To make sure Ruby would take continuous damge while in the area we changed the sleeping mode within Ruby to 'Never Sleep'. The next step is to add an invinsability function to Ruby so that the health isn't instantly depleated.
Comments
Post a Comment