Week 6: Becoming Mortal
April 6, 2024
Hello and welcome to the 6th week of my senior project! As of this week, gravity now exists and our main character and enemy are no longer immortal. Additionally, the dialogue system is now in development and, in its current state, is just a bunch of canvases and panels layered together.
For this post’s agenda, I will be talking about how I accomplished the things mentioned above and what future me will (try to) accomplish in the next week.
Becoming Mortal
As I mentioned in the first section, our main character and enemy are no longer immortal and can now kill each other. (yay!) To achieve this, I gave the enemy projectiles and added methods for detecting anything that collides with either the enemy or main character. Finally, I added a health bar to the enemy. Below, I will be explaining how I accomplished each of these things.
Projectiles
For the projectiles, I did basically the same thing as I did for the bullet, the only difference is the script. The bullet shoots in the direction of the gun, while the projectiles shoot towards the player. In order to get them to shoot in the player’s direction, I created a game object reference to the player. However, rather than referencing the whole player gameobject, I only referenced the chest sprite. This is because transform.position, which I used to aim the projectile, is based on the pivot point of the sprite. By using the whole player gameobject, the enemy would basically be aiming at his feet, but, by using the chest sprite, It centers the aim.
And this is the final result.
HealthBar
For the enemy health bar, I created a canvas containing a healthbar frame, and two healthbar components. Then I attached a script to the canvas to animate it.
For the enemy health bar, I used a coroutine to adjust the timing of the two healthbars. Based on whether the HP is decreasing or increasing, I set the bottom or top bar to decrease first. For the second bar decrease, I used a while loop for decreasing its width to create a gradual effect.
And it turned out like this. |
Collisions
This method detects things that collide with the enemy sprite. It takes in the object that collides with it as a parameter and I then check if that object is either the player or a bullet. Based on that, I deduct player or enemy health.
Similarly, this method detects if anything collides with the projectile. If the object that collides with it is the player, it deducts player health.
Dialogue
Essentially what I have for the dialogue system now is just a bunch of panels and canvas, but I can explain what each of them does. For the dialogue scene we have two cameras instead of one. |
This allows us to have a camera that shows the UI elements and one that doesn’t. Now for the canvas, we have two of them too, main and overlay. Overlay is used for the UI elements, such as buttons, and main contains everything else that appears on screen. Within the main canvas, we have multiple layers each in charge of a different visual element. This allows me to organize my scene and keep track of different elements.
Next agenda
For next week, I plan to continue working on the dialogue system and creating some animations that will be used for the background in the side-scroller. I hope to see you next week, as I report back on my operation!
Leave a Reply
You must be logged in to post a comment.