Sponsored By

Using Unity Animation Events: Deterrence - Video Devlog 13

The thirteenth weekly devlog of Deterrence. This week I use the unity animation events to make enemies deal damage and spawn enemies for levels. And the project starts to feel like a game as pieces come together.

Matthew Gianfrancesco, Blogger

June 13, 2022

2 Min Read

A tower defense mixed with real-time strategy where you repel attacking sentient AI robots until they give up.

Using Unity Animation Events

Since the enemy robot's animation shows the unit firing twice, I decided to also use events for each fire animation that would call the enemy unit's fire method. This gave me a lot of wiggle room to make units shoot in different ways and also made it very simple to calculate unit DPS (Damage Per Second). So, I decided to make player units follow this structure as well.

Calculating DPS using Unity animations required grabbing the RuntimeAnimatorController of the units Animator. With the RuntimeAnimatorController, I can find the fire animation by name and then simply use the animation length and number of events in the animation.

Unity animation event functions don't support methods that have multiple parameters, so, to get around this, I made a method with a string parameter and pass multiple parameters separated by a comma in a large string. With this trick, I can use animation events to spawn diverse enemy groups at any start point in the level. Doing it this way will make it easier to build levels by using the animations like event timelines and using the extra functionality that comes with animations.

Starting To Feel Like A Game

Now that enemy units can deal damage to player units and buildings, and can move towards points of interest; Play testing is now starting to feel like playing a game. I'm starting to balance stats and list of functionality to implement is dwindling. The game is approaching an alpha stage and by my estimate I believe there will be an alpha version of the game within the next 2 months.

Read more about:

Daily news, dev blogs, and stories from Game Developer straight to your inbox

You May Also Like