Forum begins after the advertisement:


[General] Some bugs and fixes

Home Forums Video Game Tutorial Series Creating a Metroidvania in Unity [General] Some bugs and fixes

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #19310
    Sean Ng
    Level 2
    Participant
    Helpful?
    Up
    0
    ::

    Bugs covered

    • Boss slash not hitting player
    • Player able to spin boss during their outbreak barrage
    • Player spawning outside map when return to last platform position
    • Player flying using jump when spammed
    • THK not dying when attacks like vengeful spirit hit bringing health into negative

    Boss slash unable to hit player

    When the boss uses slash or triple slash it is unable to hit player due to variable only containing 1 collider even though it receives multiple, this causes the variable to not be the player hence the player will not be damaged.
    Collider2D _objectsToHit = Physics2D.OverlapBox(_attackTransform.position, _attackArea, 0);

    To Fix this, the Collider2D will become a array and foreach loop will check if the player collider exist within it.

    THKEvents script

    void Hit(Transform _attackTransform, Vector2 _attackArea)
    {
        Collider2D[] _objectsToHit = Physics2D.OverlapBoxAll(_attackTransform.position, _attackArea, 0);
    
        foreach (Collider2D collider in _objectsToHit)
        {
            if (collider.TryGetComponent(out Player p) && !p.Is(State.invincible))
            {
                p.TakeDamage(TheHollowKnight.Instance.damage);
                if (p.Is(State.alive))
                {
                    GameManager.Stop();
                }
            }
        }
    }

    Player spinning boss during outbreak barrage

    When the boss is in their outbreak barrage state, the player can jump into them, spinning them causing them to land upside down which makes them unable to hit the player for the most part.

    This is simple to fix, as their constraints is changed in Boss_BendDown script, instead of having it freeze position only, we’ll have it freeze all constraints.

    Boss_BendDown script code change highlighted in green.

    void OutbreakAttack()
    {
        if(TheHollowKnight.Instance.outbreakAttack)
        {
            Vector2 _newPos = Vector2.MoveTowards(rb.position, TheHollowKnight.Instance.moveToPosition,
                TheHollowKnight.Instance.speed * 1.5f * Time.fixedDeltaTime);
            rb.MovePosition(_newPos);
    
            if (TheHollowKnight.Instance.TouchedWall())
            {
                TheHollowKnight.Instance.moveToPosition.x = rb.position.x;
                _newPos = Vector2.MoveTowards(rb.position, TheHollowKnight.Instance.moveToPosition,
                    TheHollowKnight.Instance.speed * 1.5f * Time.fixedDeltaTime);
            }
    
            float _distance = Vector2.Distance(rb.position, _newPos);
            if (_distance < 0.1f)
            {
                TheHollowKnight.Instance.rb.constraints = RigidbodyConstraints2D.FreezeAll;
            }
        }
    }

    Player spawn outside map when return to last platform position

    Mainly seen when player runs into spike jumping from the main floor of cave_1, this is due to the default platform position positing to 0,0.

    We’ll fix this giving player position when game start, and exit point when transition to new scene.

    GameManager script change added in green.

    async void Start()
    {
        await Task.Delay(100);
        Bench.QuickLoad();
    
        platformingRespawnPoint = PlayerController.Instance.transform.position;
    
        // If the code gets here, we check whether we need to spawn a shade again.
        if (PlayerController.Instance != null) {
            if (globalData.shadeScene == SceneManager.GetActiveScene().name) {
                SpawnShade(globalData.shadePosition, globalData.shadeRotation);
            }
        }
    }

    SceneTransition script change added in green.

    private void Start()
    {
        if(GameManager.Instance.transitionedFromScene == transitionTo)
        {
            PlayerController.Instance.transform.position = startPoint.position;
            GameManager.Instance.platformingRespawnPoint = startPoint.position;
            StartCoroutine(PlayerController.Instance.WalkIntoNewScene(exitDirection, exitTime));
        }
        StartCoroutine(UIScreen.FadeTo(fadeColor, -1, fadeTime));
    }

    Player flying using jump

    When player spam jump, their able to jump multiple times even though they only have 1 air jump, air jump counter also doesn’t go above 1.

    Looking through there was 2 allowing jump but the first doesn’t have anything preventing it from constantly triggerring.

    PlayerController script

    void Jump() {
        if (jumpBufferCounter > 0 && coyoteTimeCounter > 0 && !Is(State.jumping)) {
            if (Input.GetButtonDown("Jump")) {
                audioSource.PlayOneShot(jumpSound);
    
                if (Grounded()) rb.velocity = new Vector3(rb.velocity.x, jumpForce);
            }
    
            Set(State.jumping, true);
        }
    
        if (!Grounded() && airJumpCounter < maxAirJumps && Input.GetButtonDown("Jump") && abilities.HasFlag(Abilities.variableJump)) {
            audioSource.PlayOneShot(jumpSound);
    
            Set(State.jumping, true);
            airJumpCounter++;
    
            rb.velocity = new Vector3(rb.velocity.x, jumpForce);
        }
    
        if (Input.GetButtonUp("Jump") && rb.velocity.y > 3) {
            Set(State.jumping, false);
            rb.velocity = new Vector2(rb.velocity.x, 0);
        }
    
        rb.velocity = new Vector2(rb.velocity.x, Mathf.Clamp(rb.velocity.y, -maxFallingSpeed, rb.velocity.y));
    
        anim.SetBool("Jumping", !Grounded());
    }

    THK not dying at negative health

    I am still not sure why it isn’t running properly the function is called which caused alive variable in TheHollowKnight script to be false which prevent the function being called again.

    I just remove the check on the alive so if it doesn’t run, the player can hit again and it will call the function again.

    The only reason I can think of is since the vengeful spirit deals 20 damage it causes the boss to go into a phase switch and death at the same time, which cause death to not run properly.

    TheHollowKnight script change highlighted in red.

    public override void EnemyGetsHit(float _damageDone, Vector2 _hitDirection, float _hitForce)
    {
        if (!stunned)
        {
            if (!parrying)
            {
                if(canStun)
                {
                    hitCounter++;
                    if(hitCounter >= 3)
                    {
                        ResetAllAttacks();
                        StartCoroutine(Stunned());
                    }
                }
                ResetAllAttacks();
                base.EnemyGetsHit(_damageDone, _hitDirection, _hitForce);
    
                if (currentEnemyState != EnemyStates.THK_Stage4)
                {
                    ResetAllAttacks(); //cancel any current attack to avoid bugs 
                    StartCoroutine(Parry());
                }
    
            }
            else
            {
                StopCoroutine(Parry());
                parrying = false;
                ResetAllAttacks();
                StartCoroutine(Slash());  //riposte
            }
        }
        else
        {
            StopCoroutine(Stunned());
            anim.SetBool("Stunned", false);
            stunned = false;
        }
        #region health to state
    
        if(health > 15)
        {
            ChangeState(EnemyStates.THK_Stage1);
        }
        if(health <= 15 && health > 10)
        {
            ChangeState(EnemyStates.THK_Stage2);
        }
        if (health <= 10 && health > 5)
        {
            ChangeState(EnemyStates.THK_Stage3);
        }
        if (health <= 5)
        {
            ChangeState(EnemyStates.THK_Stage4);
        }
        if(health <= 0 && alive)
        {
            Death(0);
        }
    
        #endregion
    
    }
Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: