Search Unity

Charge animation and physics ways

Discussion in '2D' started by ikorsa, Jun 12, 2019.

  1. ikorsa

    ikorsa

    Joined:
    Dec 7, 2017
    Posts:
    7
    Hello everyone!
    So, i started learn unity some time ago on my own, and without someone with expirience i found some troubles in figuring out ways to create something on my own. Today i want to ask you, guys, how would you do something like this little task below:

    For example, we have 2d animated character (sprites), he can walk, jump, etc. How would you make him use something like "charge attack", like, dashing forward, hitting the target and go past it for some meters. The best example of this move i would say - katana zero, level there you have to fight as Dragon in the prison. He had special attack, like charge. It shouldn't be the same, but, i hope, you got the point =)

    I can share what i has tested, but only if you ask for, cause im very new and noobish in unity/c# =) so it wouldn't be really usefull.
    In terms "how would you", i mean exactly few things:
    1. Move distance. It must be exact, lets say, 10 "meters", like transform.position.x + 10, no more no less. (im using transform.Translate, but any suggestions appritiated :3 )
    2. Animation. It's the most important. (I want it to be exactly as i planned, when i drew it, but its so hard to make it in engine.) Character dashing forward, it means it has to leave some trails or effects or something like this, and some effects must be afterwards, like swing of the blade infront of him after he stops, etc. Would it be some generic prefabs, which must be destroyed after delay? Or character sprite in animation should be with this effect? Or.. ? What is the "best" way? (also, i would like to hear how you doing this sort of things in general, like character waved his sword, created some effects around, sparks, lightning, fire, anything. this effects should be as another game object, or part of character's sprite in animation?)
    3. Ways to record damage, like you have to use some trigger between point A (where attack was started) and point B (where it ends), or change character to trigger (sounds weird, but if...), etc.

    I hope you will find this "task" interesting and will share your wisdom with me :3 thanks
     
  2. Primoz56

    Primoz56

    Joined:
    May 9, 2018
    Posts:
    369
    I was doing almost all of this manually (code) and while it worked it had many artefacts and was quite painful to manage.

    Use an Animator component, set up animations for what you want to do, use animation layers if you want multiple competing animations (eg. trails), and use animation events for determining when 'damage' is supposed to happen. You may need to use collision objects to determine when objects collide, but i still find code to be easier for that (in the Update function). I would probably just determine if and where the enemy will be hit when you start the attack, and use the animation event to delay the effect.