Forum begins after the advertisement:


[Part 3] Article Changes, Common Issues & Bugfixes

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

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #14551
    Joseph Tang
    Moderator

    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 3]

      *Article Changes*

    • 1. Enemy takes more/twice the damage due to BoxCollider2D.
    • 2. Enemy continues to move while being recoiled.
    • 3. Can carry out other actions while healing.
    • *Common Issues*

    • 4. ___ does not take damage.


    [Part 3] Melee Combat & Enemy AI Base Class

    Article Changes

    1. Enemy takes more/twice the damage due to BoxCollider2D.

    [You can choose between adding a code to the Enemy.cs or the PlayerController.cs. In the series, we have decided to go with the PlayerController.cs method, but both methods work.]

    void Hit(Transform _attackTransform, Vector2 _attackArea, ref bool _recoilDir, float _recoilStrength)
    {
        Collider2D[] objectsToHit = Physics2D.OverlapBoxAll(_attackTransform.position, _attackArea, 0, attackableLayer);
        List<Enemy> hitEnemies = new List<Enemy>();
    
        if(objectsToHit.Length > 0)
        {
            _recoilDir = true;
        }
    
        for(int i = 0; i < objectsToHit.Length; i++)
        {
            if (objectsToHit[i].GetComponent() != null)
            {
                objectsToHit[i].GetComponent<Enemy>().EnemyHit(damage, (transform.position - objectsToHit[i].transform.position).normalized, _recoilStrength);
            }
    	
            Enemy e = objectsToHit[i].GetComponent<Enemy>();
            if(e && !hitEnemies.Contains(e)) {
                e.EnemyHit(damage, (transform.position - objectsToHit[i].transform.position).normalized, _recoilStrength);
                hitEnemies.Add(e);
            }
        }
    }

    2. Enemy continues to move while being recoiled.

    [This issue is caused by a missing code]

    • Set isRecoiling to true in the Enemy.cs EnemyHit() method.
        public virtual void EnemyHit(float _damageDone, Vector2 _hitDirection, float _hitForce)
        {
            health -= _damageDone;
            if(!isRecoiling)
            {
                rb.AddForce(-_hitForce * recoilFactor * _hitDirection);
                isRecoiling = True;
            }
        }

    3. Infinite Attack Speed.

    [This issue is caused by a missing code]

    • Change private float timeBetweenAttack; to [SerializeField] private float timeBetweenAttack;. in PlayerController.cs
        [Header("Attack Settings:")]
        [SerializeField] private Transform SideAttackTransform; //the middle of the side attack area
        [SerializeField] private Vector2 SideAttackArea; //how large the area of side attack is
    
        [SerializeField] private Transform UpAttackTransform; //the middle of the up attack area
        [SerializeField] private Vector2 UpAttackArea; //how large the area of side attack is
    
        [SerializeField] private Transform DownAttackTransform; //the middle of the down attack area
        [SerializeField] private Vector2 DownAttackArea; //how large the area of down attack is
    
        [SerializeField] private LayerMask attackableLayer; //the layer the player can attack and recoil off of
    
        private float timeBetweenAttack, timeSinceAttack;
    
        [SerializeField] private float timeBetweenAttack;
        private float timeSinceAttack;

    timeBetweenAttack is the attack cooldown, however it is kept at 0 by default as it has not been set to a value and there is no influence to this value through code.


    Common Issues

    4. ___ does not take damage.

    • Ensure the Player has the “Player” tag assigned to them.
    • Set the Player’s “Attackable Layer” to “Attackable”
    • Ensure the Enemy has the “Attackable” Layer assigned to them.

    Assign the “Player” tag to the Player GameObject.

    Set “Attackable Layer” to “Attackable”.

    Assign the “Attackable” layer to the Enemy GameObject.


    That will be all for Part 3.
    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: