Forum begins after the advertisement:


[Part 3] Player is able to flip around while attacking

Home Forums Video Game Tutorial Series Creating a Metroidvania in Unity [Part 3] Player is able to flip around while attacking

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #15743
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    louie2 has a question for us on YouTube:

    either i’ve done something wrong or the recoil code seems to overlook that if you change directions mid recoil you’ll change the way you’re facing and thus be able to switch the recoil direction. is this addressed in a later part? thanks
    #15744
    Terence
    Level 30
    Keymaster
    Helpful?
    Up
    0
    ::

    I’m not well aquainted with the series, so I’m not sure if it is covered in a later part, but you can update your code so that the Flip() function cannot run when you are attacking, like so:

    void Flip()
    {
        // Prevent turning for 1 second after attacking.
        if(timeSinceAttack < 1f) return; 
        if (xAxis < 0)
        {
            transform.localScale = new Vector2(-Mathf.Abs(transform.localScale.x), transform.localScale.y);
        }
        else if (xAxis > 0)
        {
            transform.localScale = new Vector2(Mathf.Abs(transform.localScale.x), transform.localScale.y);
        }
    }

    You will need to replace the 1f with the amount of time you want to disable attack for.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: