Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Dashing Ability

Discussion in 'Scripting' started by Zolaire, Aug 22, 2020.

  1. Zolaire


    May 23, 2020
    Hello, I have a problem I'am trying to recreate Master Yi - Alpha Strike, in unity.
    The code is what I have so far, I thought it was pretty simple but I guess not, can anyone help?

    In case you don't wish to watch the video his ability strikes all enemies in an area, I need it to strike all enemies in the level.
    I have it set up so that the Dashing is equal to when the player deals damage, so I need that to be active.

    Code (CSharp):
    2. if (player.GetComponent<Movement>().ultProcess >= player.GetComponent<Movement>().ultActivate)
    3.         {
    4.             Time.timeScale = 0.3f;
    5.             player.GetComponent<Movement>().isUlting = true;
    6.             GameObject[] enemyPos = GameObject.FindGameObjectsWithTag("Enemy");
    7.             player.GetComponent<Movement>().dashing = true;
    8.             foreach (GameObject e in enemyPos)
    9.             {
    10.                 player.transform.position = e.transform.position;
    11.             }
    12.             player.transform.position = new Vector3(0, 0, 0);
    13.             player.GetComponent<Movement>().ultProcess = 0;
    14.             player.GetComponent<Movement>().isUlting = false;
    15.             Time.timeScale = 1;
    16.         }
  2. Yoreki


    Apr 10, 2019
    You have to keep in mind that code is run sequentially. So all of your code example happens after each other.. in the same frame. Effectively, setting timescale to 0.3, then back to 1, or setting your position or bools to true or false and back, does absolutely nothing unless spread over multiple frames. So you'll have to do just that.

    First implement something that lets you visually dash between two points. This will involve an animation and lerping positions. We will use that functionality below.
    When activating the ability, get yourself a list of target enemies and save them as Queue<Enemy> in the order they are supposed to be attacked. Also enter some state (see: Statemachines) in which you are dashing.
    While in the dashing state, dash from your old position to the position of the first enemy in the Queue (again, this effectively only requires lerping a position and playing some animation). When that position is reached, deal damage to that enemy, save its position as 'new old position', dequeue the enemy from the queue, and dash towards the next one. Leave the dashing state once the Queue contains no more elements, that's when the ability ends.

    Hope this helps.
    Zolaire, PraetorBlue and eses like this.