This shows you the differences between two versions of the page.
pjv:laboratoare:en:03 [2019/10/23 15:12] alexandru.gradinaru |
pjv:laboratoare:en:03 [2019/10/23 15:19] (current) alexandru.gradinaru [2D animations in Unity] |
||
---|---|---|---|
Line 23: | Line 23: | ||
=== Animator Controller === | === Animator Controller === | ||
- | Urmatorul pas este sa configuram aceste animatii astfel incat sa le putem folosi, si sa putem tranzitiona intre ele. Pentru acest lucru, vom folosi un ''Animator Controller''. Acest controller functioneaza ca un automat de stari, fiecare stare putand fi o animatie. | + | After making animations (check the tutorials above) the next step is to configure these animations so that we can use them, and be able to transition between them. For this, we will use an ''Animator Controller''. This controller works as a state machine, each state being an animation. |
- | Pentru a folosi animatiile se pot adauga cu drag-and-drop in Animator. | + | To use the animations you can add drag-and-drop in the Animator. |
{{ :pjv:laboratoare:unitystates5.png?direct&300 |}} | {{ :pjv:laboratoare:unitystates5.png?direct&300 |}} | ||
- | Pentru animatii fluente si controlate, trebuie sa definim tranzitii intre acestea. Tranzitiile au mai multe proprietati, printre care timpi de activare, conditii etc. | + | For fluent and controlled animations, we must define the transitions between them. Transitions have many properties, including activation times, conditions, etc. |
{{ :pjv:laboratoare:unitystates11.jpg?direct&300 |}} | {{ :pjv:laboratoare:unitystates11.jpg?direct&300 |}} | ||
{{ :pjv:laboratoare:unitystates10.png?direct&300 |}} | {{ :pjv:laboratoare:unitystates10.png?direct&300 |}} | ||
{{ :pjv:laboratoare:unitystates12.jpg?direct&300 |}} | {{ :pjv:laboratoare:unitystates12.jpg?direct&300 |}} | ||
- | Conditiile sunt folosite pentru a controla cand are loc o tranzitie. Spre exemplu, putem folosi un parametru de stare, pentru a trece dintr-o animatie in alta, sau alte conditii (spre exemplu daca este pe sol, in aer, primeste damage etc.) | + | Conditions are used to control when a transition occurs. For example, we can use a state parameter to move from one animation to another, or other conditions (for example if it is on the ground, in the air, receives damage, etc.) |
- | Spre exemplu putem folosi urmatoarea conventie pentru un parametru de stare: | + | For example, we can use the following convention for a status parameter: |
* ken_idle = 0 | * ken_idle = 0 | ||
* ken_walk = 1 | * ken_walk = 1 | ||
Line 93: | Line 93: | ||
</code> | </code> | ||
- | === Animatie fundal === | + | === Background animation === |
To animate the background of a 2D game, we can alter the position of the texture. Thus, we must define a material with a texture, and apply it on an object (usually a quad). After that we have at our disposal the Render component in which we can access the material and implicitly the textures, to which we can add an offset, depending on the position of the character, or a movement in time, etc. | To animate the background of a 2D game, we can alter the position of the texture. Thus, we must define a material with a texture, and apply it on an object (usually a quad). After that we have at our disposal the Render component in which we can access the material and implicitly the textures, to which we can add an offset, depending on the position of the character, or a movement in time, etc. | ||
Line 113: | Line 113: | ||
For shooting animation, a status is generally used to update the player's animation, and the projectile is generated as follows (recommended): | For shooting animation, a status is generally used to update the player's animation, and the projectile is generated as follows (recommended): | ||
- | * A script is added to the weapon (which is on the scene) that manages the projectile generation and direction | + | * A script is added to the weapon (which is on the scene) that manages the projectile generation and direction |
- | * Starting from the location of the weapon, a projectile (using the Instantiate function, already studied) is instantiated (prefab as a rule, it must not already exist on the scene, using the position of the weapon). The projectile has attached a script containing details of speed, damage, etc. | + | * Starting from the location of the weapon, a projectile (using the Instantiate function, already studied) is instantiated (prefab as a rule, it must not already exist on the scene, using the position of the weapon). The projectile has attached a script containing details of speed, damage, etc. |
- | * The projectile has a continuous translational motion in one direction, until it reaches a limit or collider when it triggers | + | * The projectile has a continuous translational motion in one direction, until it reaches a limit or collider when it triggers |
=== Animations and scene instancing ==== | === Animations and scene instancing ==== | ||
Line 138: | Line 138: | ||
</code> | </code> | ||
- | === Colision === | + | === Collision === |
For collision detection a collider2D can be used. For easy interaction, a Trigger can be generated at the collision event by ticking the ''Trigger'' box in the component. After that you can retrieve the event and the object with which the collision is made. | For collision detection a collider2D can be used. For easy interaction, a Trigger can be generated at the collision event by ticking the ''Trigger'' box in the component. After that you can retrieve the event and the object with which the collision is made. |