top of page
Writer's pictureZack Scanlon

Animating in unity

Updated: Nov 30, 2020

In unity i imported my floor sprite and put a 2d box collider on it so that it has collision properties i then made the object a prefab so that i can instance it multiple times once that was done i used it to make a floor for my sprite. I took my knight sprites and in the inspector changed the sprite mode from multiple to single. Using the slice editor i put in my artworks details so that it would splice up my sprite. For the knight sprite i added a rigid body and capsule collider so that it actually interacts with the floor. Then i put a animator component on the knight sprite and then created an animation and animation controller and then put the animation i created in the controller and the animation would play. I then created a script so give my character movement i created a variable to control my characters walk speed. However an issue is that no matter what direction the character my character is walking it only faces one direction. One possible solution would be using transformations to change the direction however it gets messy when playing with transformation. So instead accessing the sprite renderer and using a conditional if statement to determine when the animation should flip. I used a boolean to determine weather or not the character is facing left or right i set the bool to true to start with meaning that is facing right to begin with. Then using a if else statement to dictate what direction the character is facing when the movement buttons are pressed.


 

For adding a running animation i again sliced the run animation and create an animation out of it and then added it to the animation editor at first i couldn't remember how to make connections in the animator but after asking it was right clicking and selecting make transition to link between the idle and running animation back and forth between them, i also created a new float in the parameters area. The next part was quite abstract but with some explanation it made more sense as it was explained as it was blending between the idle and running animation so dragged the blue bar to end and collapsed to so the animations instantly change between them. To tell unity when to change between them i went into the code and created an animator variable and declared it, in the void update and under the movement speed used the newspeed parameter to tell when to trigger the idle and running animation. This was quite a weird process but after going through it, it made much more sense being able to apply it.



1 view0 comments

Recent Posts

See All

Comentários


bottom of page