Forum begins after the advertisement:


[Part 4] Crashes When Dashing and Taking Damage

Home Forums Video Game Tutorial Series Creating a Metroidvania in Unity [Part 4] Crashes When Dashing and Taking Damage

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #15878
    Ferral Child
    Participant
    Helpful?
    Up
    0
    ::

    Hello,

    (Im at the start of Part 4)

    I’m a little confused. For whatever reason whenever I dash into an enemy it causes the play window in Unity to freeze. It seems to be something to do with the particle effects- as when I delete them it doesn’t crash, but the invincibility doesn’t turn off. (Keeps flashing).

    I would like to keep the particle effects, but I don’t know how to stop the crashing. Any advice?

    #15883
    Joseph Tang
    Moderator
    Helpful?
    Up
    1
    ::

    This is covered in Part 6. When your HitStopTime() freezes the game when you get hit, RestoreTimeScale() (Or whatever the method that is supposed to restore the time is named for you) is called.

    Howver, it only works when it is active in Update(). Unfortunately, we seem to have placed it below the return line for when you dash. Therefore, when you dash and get hit, time does not resume and thus you “crash”.

    The reason you flash is because StopTakingDamage() instantiates the blood particles. But if that particle doesn’t exist, it fails to continue the rest of its code, causing an error and leaving you as invincible, thus making FlashWhileInvincible() on.

    So, just put your RestoreTimeScale() above in the Update() method as it doesn’t need to be stopped anytime.

        void Update()
        {
            ...
            RestoreTimeScale();
    
            if (pState.dashing) return;
            RestoreTimeScale();
            ...
        }
    
    #15898
    Ferral Child
    Participant
    Helpful?
    Up
    1
    ::

    This fixed the freezing- thank you so much!

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

Go to Login Page →


Advertisement below: