Dashing Ability

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.

if (player.GetComponent<Movement>().ultProcess >= player.GetComponent<Movement>().ultActivate)
        {
            Time.timeScale = 0.3f;
            player.GetComponent<Movement>().isUlting = true;
            GameObject[] enemyPos = GameObject.FindGameObjectsWithTag("Enemy");
            player.GetComponent<Movement>().dashing = true;
            foreach (GameObject e in enemyPos)
            {
                player.transform.position = e.transform.position;
            }
            player.transform.position = new Vector3(0, 0, 0);
            player.GetComponent<Movement>().ultProcess = 0;
            player.GetComponent<Movement>().isUlting = false;
            Time.timeScale = 1;
        }

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 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.

3 Likes