- Home /
2D attack animation for Pokemon battle system
So as a way to learn Unity and its various tools, I've made a pokemon battle system. I know what it needs and should look like, so I figured it's a great way to learn.
I have most of everything in place, but having some small issues with the animations for attacks. How would you approach this? I'm not looking for code, just what way you think would be best?
Currently I have a game object for each attack, that has an animator attached. The issue is, as I'm sure you would know, it can only really be in one spot. The animation runs on just one pokemon regardless of it being the attacking or defending pokemon.
What I would like to do, is have an animator over each pokemon and set what animation should play in that animator based on the attack and who the defender is. But it looks like that's not really possible with code, unless I'm wrong. It seems like you can't really set all the things the animator needs to know about, and it's not as simple as just changing the animation, but the controller too.
The other two solutions I could think of is just make copies of each attack animation and place them over each pokemon. This seems sloppy. Which lead me to understand the way it's set up is sloppy. If I were to develop this battle sim further it would end up having hundreds of attack animations in an idle state just sitting over each pokemon waiting to go off. That seems wrong.
The other solution would be to make the attack animations prefabs, and instaniatie them over the pokemon when its attack is called. This would give me the desired effect, but it seems excessive to make every animation a prefab. Maybe I'm wrong and this is the perfect solution and is exactly what prefabs are meant to be created and used for.
So how would you tackle the same desired effect? You would need to have an attack animation play over a target and that animation needs to be different based on the attack used. I really want to use the "just change the animation that can play in an animator" with code, but it looks like I can't. If I'm wrong, please let me know.
Thanks in advance for just reading my question and giving it consideration. I know theres a lot of questions asked everyday, and I did my best to scour through them looking for a solution to my problem, but couldn't find a question that was close enough to mine. I'm sure there's one out there, so sorry if this is a repetitive question.
Can't you make a Pokemon prefab ins$$anonymous$$d of creating animations for every single one? Apologies if this wouldn't work, I don't really use the Animation system.
I think I need to provide some further clarification in my question. $$anonymous$$aking the Pokemon prefabs wouldn't really solve my issue. The issue is that each attack in the game will have a special effect animation. Like the little flame from Ember or the splash of water from Water Gun. Currently, each attack has a GameObject with an animator attached to control the attack animations. However, there is only one version of each attack, so when I create the animation, it's just going to appear in that one location. I'd have to make copies of each attack, or make the attacks prefabs. Honestly, I should do that because if I were to set up Power Points for each attack currently, they'd be shared between all Pokemon using that move, lol. But by making each Pokemon a prefab, and each attack a prefab assigned to that one Pokemon, would make it so that Attack and its PP would be tied to that Pokemon.
I'm leaning more towards the Prefab Animation idea, seeing how I should probably have the attack itself be a prefab anyways. That way, I can instantiate the prefab animation right on top of the active Pokemon being attacked with no issues.
However, I was curious just how others would approach this same system, as maybe I'm over thinking and missing out on a more simple solution.
And thank you for your comment. I still have a lot to learn, and appreciate you taking the time to help.
Answer by surfuay · Mar 13, 2019 at 08:18 PM
it's been a while since i've done multiple animations on one sprite, but if i remember you will make a separate animation for each occurrence and it will call for a specific animation (i don't want to say trigger because that is one of may instances that will call for an animation) based on the trigger/bool/toggle/button etc that you set for it.
this all takes place inside the animator controller. so lets say you have an attack animation, an injured animation, and a "static" animation for 2 pokemon that are fighting Charmander and Bulbasaur. i assume you have a code for receiving damage as well.
So inside Char's controller you have 3 animations all coming off him for their respective moments and Bulb's as well.
Char attacks which calls the attack animation, Bulb receives damage which call the injured animation, but both of those happen inside each respective prefabs controller, you won't be able to call Bulb's injured in Char's attack. Char attacking is independent of Bulb, it's that Bulb received damaged which called the injured animation not the Char attack that called it.
https://www.studica.com/blog/unity-tutorial-animator-controllers
this is a pretty nice picture walkthrough, i can't find the first one I had ever used to learn this. sorry
Thanks for your answer. I checked out the tutorial you provided, and that's about where my knowledge of animation and the animator currently is. I think I need to clarify a bit how I'm setting up the attacks. I'm not talking about changing the animation of the Pokemon itself, but I'm talking about the effects for all the attacks. So the small flame that appears when you use Ember or a splash of water with Water Gun. These are animations for the attacks themselves.
If I'm following you though, you might be suggesting to set up the animators for each Pokemon to have all the animations from the different attacks in the Pokemon's animator? That seems like a lot of work. I mean, right now it wouldn't be so bad with only 10 attacks, but if I were to expand on this battle simulator to include all the attacks, that would be hundreds of attacks in both active Pokemon's animators.
If that's honestly how you think the best way to approach it would be, I honestly think making prefabs for the attack animations would be the better path. If that's not what you meant though, I would love to hear some clarification.
Thanks again for taking the time to answer and provide a source! I appreciate the effort.
I think if you're talking about the attacks themselves, I would just do a prefab. so I have an app where the player has multiple power ups moves etc. depending on what type of action it is I either instantiate a prefab on a buttons click/mouse click/touch or I set the prefab itself as a child to the parent (like putting a shield on the player) and when it's being used it's set to active. those are the 2 ways that I like to have actions that are "outside" the player to be done. I would not create 8 million animations of attacks for a single prefab tho, especially if they'll be recycled like ember for char and growlith
its sound like you are talking about pokemon fusion It seems too interesting that you can add the 2 pokemons and get an exclusive one as a pokemon fusion as pokemon combiner .having also a battle option in which you can utilize the water, explosion, web, fires, and clouds of dust.