|
Post by Animator on Jul 29, 2018 15:12:30 GMT
I am trying to add animations to walking with sprites. I added a renderer to the unit prefab, and used animator.play and I set idle animation here in an update loop in the unit script. I did the same in the commands selection, endfacing, etc. I am having trouble getting the walking correct. I put it in the movementstate but......because the unit is using update to do the idle change direction. They are fighting each other for control it seems, but I can not seem to get the walking to override the idle. Where would you recommend putting the animation controls? I am quite lost.
|
|
|
Post by Admin on Jul 30, 2018 13:55:28 GMT
Look for the places in code where I use a tweener to move either the position or rotation of a unit. That is where the code for updating an animation controller should probably go. Moving the sprite may end up using the same tweener code, although you may wish add something at the same location to enable / disable a toggle on the animation controller to allow some sort of transition within the animator to go from an idle sequence to a walk sequence. I would probably strip out any rotation tweener, but would replace it with some sort of value assignment on the animation controller that would cause a transition to the proper sprite sequence based on the new direction information.
So, in other words, most of the sprite work should probably be handled by the animation controller in Unity based on some sort of exposed toggle or value field, and you would update those values based on events in the animation sequences I had created programmatically.
|
|
|
Post by Animation on Jul 30, 2018 14:52:00 GMT
That makes sense, I will look closer at the tweener code then. How about for attack and spell animations? I was trying to add them to the perform ability state in a new method before the apply method, but am not able to get it to work. I know I can get the skill name being used so I should be able to animate based on that I thought.
Would it be better as a new script on the ability itself and then add an animator to that? Then I can get the name of attacker and defender to shoot a fire bolt for example?? Animation coding is more advanced than I thought.
|
|
|
Post by Admin on Jul 30, 2018 21:04:48 GMT
For character animations like magic spells or shooting, I would try to use either a keyframe event on the animation itself and / or a special monobehavior on the various animation controller states so I would know when it entered, and then use the callback as an opportunity to do anything dynamic or special. For example, I might have a generic raise your hand to do a magic spell animation, then at the hand is raised keyframe, I could instantiate some sort of magic special fx object with its own callback to let me know when it completes playing. Finally, I would have the original animation controller transition back to idle, and exit to the next state. Or something like that. Yes, it can get pretty advanced, and a lack of good free art assets just complicates the problem. Good luck though! Unity has some good tutorials (like the 2D rogue-like) for working with sprite animations if you get stuck.
|
|