Forum begins after the advertisement:

[Part 6] Article Changes, Common Issues & Bugfixes

Home Forums Video Game Tutorial Series Creating a Metroidvania in Unity [Part 6] Article Changes, Common Issues & Bugfixes

Viewing 1 post (of 1 total)
  • Author
  • #14615
    Joseph Tang

    This is an update post to summarize the changes made to the content of the Metroidvania series.
    Additionally, this post is to compile and go through some common issues that viewers and readers may face when following the Metroidvania series, as well as some solutions that may fix or solve the issues.

    Some solutions given will also be under the assumptions that the code for the mechanic is 1:1 for the relevant part.

    In this post, we will go through
    [Part 6]

      *Article Changes*

    • 1. Bat doesn’t stop chasing and gets recoiled infinitely.
    • 2. Hit by spikes freezes the game.
    • 3. Bat corpse can be attacked and recoils player.

    [Part 6] Enemies, Spikes, and an Advanced Camera

    Article Changes

    1. Bat doesn’t stop chasing and gets recoiled infinitely.

    [This is caused by missing code that lets the Bat return to an Idle state from Chase state. Furthermore, there is no velocity change code to change the Bat’s recoil velocity after being recoiled.]

    • In Bat.cs script, add if(_dist > chaseDistance) {ChangeState(EnemyStates.Bat_Idle);} under case EnemyStates.Bat_Chase: before break;. This should change the Bat to an Idle state if the player exits it’s chaseDistance.
    • Add a code under case EnemyStates.Bat_Idle to reset it’s velocity, rb.velocity = new Vector2(0, 0);. This will let the Bat stabilize its velocity and stop recoiling without needing to be stopped by a collision.
                case EnemyStates.Bat_Idle:
                    rb.velocity = new Vector2(0, 0);
                    if(_dist < chaseDistance)
                case EnemyStates.Bat_Chase:
                    rb.MovePosition(Vector2.MoveTowards(transform.position, PlayerController.Instance.transform.position, Time.deltaTime * speed));
                    if(_dist > chaseDistance)

    2. Hit by spikes freezes the game.

    [This is caused by “IEnumerator RespawnPoint()” in Spikes.cs scaling time to 0 and using “WaitForSeconds”]

    • Change all “WaitForSeconds” codes in Spikes.cs to “WaitForSecondsRealTime”. This allows the enumerator to continue as intended while in stopped time without freezing the game.
        IEnumerator RespawnPoint()
            yield return new WaitForSeconds WaitForSecondsRealtime(1f);
            yield return new WaitForSeconds WaitForSecondsRealtime(UIManager.Instance.sceneFader.fadeTime);

    3. Bat corpse can be attacked and recoils player.

    [There are different ways to solve this bug but the simplest is to change the Bat’s layer to anything other than “Attackable”.]

    • First, create a new layer, and call it “IgnorePlayer” or something identifiable.
    • In Bat.cs, under ChangeCurrentAnimation() add int LayerIgnoreRaycast = LayerMask.NameToLayer("Ignore Raycast"); gameObject.layer = LayerIgnoreRaycast; to the If statement for the death state:
    • Go to Edit > Project Settings > Physics2D > Layer Collision Matrix. Here you can set collision based on Layers.
    • Then, turn off collision for both “Default”, “Attackable” & “Ignore Player”. This prevents the corpse from blocking enemies, stacking on each other and player’s movement and attacks.
        protected override void ChangeCurrentAnimation()
            anim.SetBool("Idle", GetCurrentEnemyState == EnemyStates.Bat_Idle);
            anim.SetBool("Chase", GetCurrentEnemyState == EnemyStates.Bat_Chase);
            anim.SetBool("Stunned", GetCurrentEnemyState == EnemyStates.Bat_Stunned);
            if(GetCurrentEnemyState == EnemyStates.Bat_Death)
                int LayerIgnoreRaycast = LayerMask.NameToLayer("Ignore Player");
                gameObject.layer = LayerIgnoreRaycast;

    Edit > Project Settings > Physics2D > Layer Collision Matrix

    Note: Depending on your game setup, change the Layers to however you feel is needed.

    That will be all for Part 6.
    Hopefully this can help you on any issues you may have. However, if you find that your issues weren’t addressed or is a unique circumstance, you can submit a forum post to go into detail on your problem for further assistance.

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.

Go to Login Page →

Advertisement below: