In Attacks array why we set the index starting from 1 not 0?

so i done the video and its working fine but i dont understand how its working for example in the index
we assigned in editor index starting from 1 and end in -1

 public PlayerAttackingState(PlayerStateMachine stateMachine, int attackIndex) : base(stateMachine)
    {
        attack = stateMachine.Attacks[attackIndex];
    }

we take the attack index and store in attack , but our first attack index is 1 look at 14:23 min
and the last one is -1

so when we switch the state we pass in consturctor -1 and its supposed to be null and attack should be null

 stateMachine.SwitchState
        (
            new PlayerAttackingState
            (
                stateMachine,
                attack.ComboStateIndex
            )
        );

but its all working fine i dont understand how its working can someone explain to me ?

It doesn’t start at 1, it starts at 0. The first attack is at 0. The 1 we enter in the inspector is the attack we want to transition to when this one is complete, so from 0, it will transition to attack at index 1 (which we specified in the inspector). From attack 2 (index 1), it will transition to attack 3 (index 2 as specified in the inspector) and in attack 3, we have a -1 which specifies that there is no more attacks to transition to.


Edit I’ll try to make it a little clearer

In the previous video, we switched to the attack state in the PlayerTargetingState. In here we specified 0. So, when the combo starts it always picks the attack at index 0 first. Then, when it is time to continue to the next attack, it looks at the attack in index 0 and checks to see which attack it should do next. This is the ‘1’ we specified in the inspector, so it transitions to the attack at index 1. The same thing then happens again. When it is time to continue to the next attack it looks at the attack in index 1 to see which attack it should go to. This is index 2 that we specified in the inspector. So it transitions to the attack in index 2, and so on. The last attack has a -1. This specifies that there are no more attacks to transition to, so just stop there

1 Like

Yess its clear now thank you so much !

It’s my pleasure.

Nathan mentions that the reason he did this was so that we can rearrange the combos. You could swap the values 1 and 2 around and then it will do attacks 0, 2, 1 - which may look strange - but it will then attack in that sequence

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms