Forum begins after the advertisement:


[Part 10] Boss Problems

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #15082
    Mr Thinker
    Participant
    Helpful?
    Up
    0
    ::

    My Boss is not working properly, more precisly the OutBreak, Barrage, Dive and Bounce.
    In the Outbreak he wont leave the Ground i’ve tried putting its gravity scale to 1 but it did not work, the scale is set to 5 now but still does not work same to the Barrage attack.
    In the Dice attack it bugs and tries to get to the ground or when it works only creates the pillars in one direction.
    At the Bounce he just does not leave the Ground at all and gets stuck in there.
    Please help

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class FinalBossGrog : Enemy
    {
        public static FinalBossGrog Instance;
    
        [SerializeField] GameObject slashEffect;
    
        [SerializeField] public Transform SideAttackTransform;
        [SerializeField] public Vector2 SideAttackArea;
    
        [SerializeField] public Transform UpAttackTransform;
        [SerializeField] public Vector2 UpAttackArea;
    
        [SerializeField] public Transform DownAttackTransform;
        [SerializeField] public Vector2 DownAttackArea;
    
        public float attackRange;
        public float attackTimer;
    
        [HideInInspector] public bool facingRight;
    
        [Header("Ground Check Settings")]
        [SerializeField] public Transform groundCheckPoint;
        [SerializeField] private float groundCheckY = 0.2f;
        [SerializeField] private float groundCheckX = 0.5f;
        [SerializeField] private LayerMask whatIsGround;
    
        int hitCounter;
        bool stunned, canStun;
        bool alive;
    
        [HideInInspector] public float runSpeed;
    
        public GameObject impactParticle;
    
        float bloodCountDown;
        float bloddTimer;
    
        private void Awake()
        {
            if(Instance != null && Instance != this)
            {
                Destroy(gameObject);
            }
            else
            {
                Instance = this;
            }
        }
        // Start is called before the first frame update
        protected override void Start()
        {
            base.Start();
            sr = GetComponentInChildren<SpriteRenderer>();
            anim=GetComponentInChildren<Animator>();
            ChangeState(EnemyStates.FBG_Stage1);
            alive = true;
        }
    
        public bool Grounded()
        {
            if(Physics2D.Raycast(groundCheckPoint.position, Vector2.down, groundCheckY, whatIsGround)
                || Physics2D.Raycast(groundCheckPoint.position +  new Vector3(groundCheckX,0,0), Vector2.down, groundCheckY, whatIsGround)
                || Physics2D.Raycast(groundCheckPoint.position + new Vector3(-groundCheckX, 0, 0), Vector2.down, groundCheckY, whatIsGround))
            {
                return true;
            }
            else
            {
                return false;
            }
              
        }
    
        private void OnDrawGizmos()
        {
            Gizmos.color = Color.red;
            Gizmos.DrawWireCube(SideAttackTransform.position, SideAttackArea);
            Gizmos.DrawWireCube(UpAttackTransform.position, UpAttackArea);
            Gizmos.DrawWireCube(DownAttackTransform.position, DownAttackArea);
        }
    
        // Update is called once per frame
        protected override void Update()
        {
            base.Update();
            if(health<=0 && alive)
            {
                Death(0);
            }
    
            if (!attacking)
            {
                attackCountDown-=Time.deltaTime;
            }
            if (stunned)
            {
                rb.velocity = Vector2.zero;
            }
    
            bloodCountDown-=Time.deltaTime;
            if (bloodCountDown <= 0 && (currentEnemyState != EnemyStates.FBG_Stage1 && currentEnemyState != EnemyStates.FBG_Stage2))
            {
                GameObject _particle = Instantiate(particle, groundCheckPoint.position, Quaternion.identity);
                Destroy(_particle, 3f);
                bloodCountDown = bloddTimer;
            }
        }
        public void Flip()
        {
            if(PlayerController.Instance.transform.position.x < transform.position.x && transform.localScale.x > 0)
            {
                transform.eulerAngles = new Vector2(transform.eulerAngles.x,180);
                facingRight = false;
            }
            else
            {
                transform.eulerAngles = new Vector2(transform.eulerAngles.x, 0);
                facingRight = true;
            }
        }
    
        protected override void UpdateEnemyState()
        {
            if(PlayerController.Instance != null)
            {
                switch (GetCurrentEnemyState)
                {
                    case EnemyStates.FBG_Stage1:
                        canStun = true;
                        attackTimer = 6;
                        runSpeed = speed;
                        break;
    
                    case EnemyStates.FBG_Stage2:
                        canStun = true;
                        attackTimer = 5;
                        break;
    
                    case EnemyStates.FBG_Stage3:
                        canStun = false;
                        attackTimer = 8;
                        bloddTimer = 5f;
                        break;
    
                    case EnemyStates.FBG_Stage4:
                        canStun = false;
                        attackTimer = 10;
                        runSpeed = speed / 2;
                        bloddTimer = 1.5f;
                        break;
                }
            }
        }
        protected override void OnCollisionStay2D(Collision2D _other)
        {
            
        }
    
        #region attacking
        #region variables
        [HideInInspector] public bool attacking;
        [HideInInspector] public float attackCountDown;
        [HideInInspector] public bool damagedPlayer=false;
        [HideInInspector] public bool parrying;
    
        [HideInInspector] public Vector2 moveToPosition;
        [HideInInspector] public bool diveAttack;
        public GameObject divingCollider;
        public GameObject pillar;
    
        [HideInInspector] public bool barrageAttack;
        public GameObject barrageDarkBall;
        [HideInInspector] public bool outbreakAttack;
    
        [HideInInspector] public bool bounceAttack;
        [HideInInspector] public float rotationDirectionToTarget;
        [HideInInspector] public int bounceCount;
    
        #endregion
    
        #region Control
        public void AttackHandler() 
        {
            if(currentEnemyState== EnemyStates.FBG_Stage1)
            {
                if(Vector2.Distance(PlayerController.Instance.transform.position, rb.position) <= attackRange)
                {
                    StartCoroutine(TripleSlash());
                }
                else
                {
                    StartCoroutine(Lunge());                
                }
            }
    
            if (currentEnemyState == EnemyStates.FBG_Stage2)
            {
                if (Vector2.Distance(PlayerController.Instance.transform.position, rb.position) <= attackRange)
                {
                    StartCoroutine(TripleSlash());
                }
                else
                {
                    int _attackChosen = Random.Range(1, 3);
    
                    if (_attackChosen == 1)
                    {
                        StartCoroutine(Lunge());
                    }
                    if (_attackChosen == 2)
                    {
                        DiveAttackJump();
                    }
                    if (_attackChosen == 3)
                    {
                        BarrageBendDown();
                    }
                }
            }
    
            if (currentEnemyState == EnemyStates.FBG_Stage3)
            {
                int _attackChosen = Random.Range(1, 4);
    
                if (_attackChosen == 1)
                {
                    OutbreakBendDown();
                }
                if (_attackChosen == 2)
                {
                    DiveAttackJump();
                }
                if (_attackChosen == 3)
                {
                    BarrageBendDown();
                }
                if (_attackChosen == 4)
                {
                    BounceAttack();
                }
            }
    
            if (currentEnemyState == EnemyStates.FBG_Stage3)
            {
                if (Vector2.Distance(PlayerController.Instance.transform.position, rb.position) <= attackRange)
                {
                    StartCoroutine(Slash());
                }
                else
                {
                    BounceAttack();
                }
            }
        }
    
        public void ResetAllAttacks()
        {
            attacking = false;
            StopCoroutine(TripleSlash());
            StopCoroutine(Lunge());
            StopCoroutine(Parry());
            StopCoroutine(Slash());
    
            diveAttack = false;
            barrageAttack = false;
            outbreakAttack = false;
            bounceAttack = false;
        }
        #endregion
    
        #region Stage 1
    
        IEnumerator TripleSlash()
        {
            attacking = true;
            rb.velocity = Vector2.zero;
    
            anim.SetTrigger("Slash");
            SlashAngle();
            yield return new WaitForSeconds(0.3f);
            anim.ResetTrigger("Slash");
    
            anim.SetTrigger("Slash");
            SlashAngle();
            yield return new WaitForSeconds(0.5f);
            anim.ResetTrigger("Slash");
    
            anim.SetTrigger("Slash");
            SlashAngle();
            yield return new WaitForSeconds(0.2f);
            anim.ResetTrigger("Slash");
    
            ResetAllAttacks();
        }
    
        void SlashAngle()
        {
            if(PlayerController.Instance.transform.position.x > transform.position.x
                || PlayerController.Instance.transform.position.x < transform.position.x)
            {
                Instantiate(slashEffect, SideAttackTransform);
            }
            else if(PlayerController.Instance.transform.position.y > transform.position.y)
            {
                SlashEffectAtAngle(slashEffect,90,UpAttackTransform);
            }
            else if (PlayerController.Instance.transform.position.y < transform.position.y)
            {
                SlashEffectAtAngle(slashEffect, -90, DownAttackTransform);
            }
        }
    
        void SlashEffectAtAngle(GameObject _slashEffect, int _effectAngle, Transform _attackTransform)
        {
            _slashEffect = Instantiate(_slashEffect, _attackTransform);
            _slashEffect.transform.eulerAngles = new Vector3(0, 0, _effectAngle);
            _slashEffect.transform.localScale = new Vector2(transform.localScale.x, transform.localScale.y);
    
        }
        IEnumerator Lunge()
        {
            Flip();
            attacking = true;
            anim.SetBool("Lunge", true);
            yield return new WaitForSeconds(1f);
            anim.SetBool("Lunge", false);
            damagedPlayer = false;
    
            ResetAllAttacks();
        }
    
        IEnumerator Parry()
        {
            attacking = true;
            rb.velocity = Vector2.zero;
            anim.SetBool("Parry", true);
            yield return new WaitForSeconds(0.8f);
            anim.SetBool("Parry", false);
            parrying=false;
            ResetAllAttacks();
        }
        IEnumerator Slash()
        {
            attacking = true;
            rb.velocity = Vector2.zero;
    
            anim.SetTrigger("Slash");
            SlashAngle();
            yield return new WaitForSeconds(0.2f);
            anim.ResetTrigger("Slash");
    
            ResetAllAttacks();
        }
        #endregion
        #region Stage 2
    
        void DiveAttackJump()
        {
            attacking = true;
            moveToPosition = new Vector2(PlayerController.Instance.transform.position.x, rb.position.y + 10);
            diveAttack = true;
            anim.SetBool("Jump", true);
        }
        public void Dive()
        {
            anim.SetBool("Dive", true);
            anim.SetBool("Jump", false);
        }
    
        private void OnTriggerEnter2D(Collider2D _other)
        {
            if(_other.GetComponent<PlayerController>() != null && (diveAttack || bounceAttack))
            {
                _other.GetComponent<PlayerController>().TakeDamage(damage * 2);
                PlayerController.Instance.pState.recoilingX = true;
            }
        }
        public void DivingPillar()
        {
            Vector2 _impactPoint = groundCheckPoint.position;
            float _spawnDistance = 3;
    
            for(int i = 0; i < 3; i++)
            {
                Vector2 _pillarSpwnPointRight = _impactPoint + new Vector2(_spawnDistance, 0);
                Vector2 _pillarSpwnPointLeft = _impactPoint + new Vector2(_spawnDistance, 0);
                Instantiate(pillar, _pillarSpwnPointRight, Quaternion.Euler(0, 0, 0));
                Instantiate(pillar, _pillarSpwnPointRight, Quaternion.Euler(0, 0, 0));
    
                _spawnDistance += 3;
            }
            ResetAllAttacks();
        }
    
        void BarrageBendDown()
        {
            attacking = true;
            rb.velocity = Vector2.zero;
            barrageAttack = true;
            anim.SetTrigger("BendDown");
        }
    
        public IEnumerator Barrage()
        {
            rb.velocity = Vector2.zero;
    
            float _currentAngle = 30f;
    
            for(int i=0; i < 10; i++)
            {
                GameObject _projectile = Instantiate(barrageDarkBall, transform.position, Quaternion.Euler(0, 0, _currentAngle));
    
                if (facingRight)
                {
                    _projectile.transform.eulerAngles = new Vector3(_projectile.transform.eulerAngles.x, 0, _currentAngle + 45);
                }
                else
                {
                    _projectile.transform.eulerAngles = new Vector3(_projectile.transform.eulerAngles.x, 180, _currentAngle);
                }
    
                _currentAngle += 5;
    
                yield return new WaitForSeconds(0.4f);
            }
            yield return new WaitForSeconds(0.1f);
    
            anim.SetBool("Cast", false);
            ResetAllAttacks();
        }
    
        #endregion
        #endregion
        #region Stage 3
        void OutbreakBendDown()
        {
            attacking = true;
            rb.velocity = Vector2.zero;
            moveToPosition= new Vector2(transform.position.x, rb.position.y+10);
            outbreakAttack=true;
            anim.SetTrigger("BendDown");
        }
        public IEnumerator OutBreak()
        {
            yield return new WaitForSeconds(1f);
            anim.SetBool("Cast", true);
    
            rb.velocity = Vector2.zero;
    
            for(int i = 0; i < 3; i++)
            {
                Instantiate(barrageDarkBall, transform.position, Quaternion.Euler(0,0,Random.Range(110,130)));
                Instantiate(barrageDarkBall, transform.position, Quaternion.Euler(0, 0, Random.Range(50, 70)));
                Instantiate(barrageDarkBall, transform.position, Quaternion.Euler(0, 0, Random.Range(260, 280)));
                yield return new WaitForSeconds(0.2f);
            }
            yield return new WaitForSeconds(0.1f);
            rb.constraints = RigidbodyConstraints2D.None;
            rb.constraints = RigidbodyConstraints2D.FreezeRotation;
            rb.velocity= new Vector2(rb.velocity.x, -10);
            yield return new WaitForSeconds(0.1f);
            anim.SetBool("Cast", false);
            ResetAllAttacks();
        }
    
        void BounceAttack()
        {
            attacking = true;
            bounceCount = Random.Range(2, 5);
            BounceBendDown();
        }
        int _bounces = 0;
        public void CheckBounce()
        {
            if(_bounces< bounceCount - 1)
            {
                _bounces++;
                BounceBendDown();
            }
            else
            {
                _bounces = 0;
                anim.Play("Boss_Run");
            }
        }
        public void BounceBendDown()
        {
            rb.velocity = Vector2.zero;
            moveToPosition = new Vector2(PlayerController.Instance.transform.position.x, rb.position.y - 10);
            bounceAttack = true;
            anim.SetTrigger("BendDown");
        }
    
        public void CalculateTargetAngle()
        {
            Vector3 _directionToTarget = (PlayerController.Instance.transform.position - transform.position).normalized;
    
            float _angleOfTarget = Mathf.Atan2(_directionToTarget.y, _directionToTarget.x) * Mathf.Rad2Deg;
            rotationDirectionToTarget = _angleOfTarget;
        }
        #endregion
        public override void EnemyHit(float _damageDone, Vector2 _hitDirection, float _hitForce)
        {
            if (!stunned)
            {
                if (!parrying)
                {
                    if (canStun)
                    {
                        hitCounter++;
                        if (hitCounter >= 5)
                        {
                            ResetAllAttacks();
                            StartCoroutine(Stunned());
                        }
                    }
                    base.EnemyHit(_damageDone, _hitDirection, _hitForce);
                    if (currentEnemyState != EnemyStates.FBG_Stage4)
                    {
                        ResetAllAttacks();
                        StartCoroutine(Parry());
                    }
                }
                else
                {
                    StopCoroutine(Parry());
                    parrying = false;
                    ResetAllAttacks();
                    StartCoroutine(Slash());
                }
            }
            else
            {
                StopCoroutine(Stunned());
                anim.SetBool("Stunned", false);
                stunned = false;
            }
    
            if (health > 20)
            {
                ChangeState(EnemyStates.FBG_Stage1);
            }
            if (health <= 15 && health>10)
            {
                ChangeState(EnemyStates.FBG_Stage2);
            }
            if (health <= 10 && health > 5)
            {
                ChangeState(EnemyStates.FBG_Stage3);
            }
            if (health <= 5)
            {
                ChangeState(EnemyStates.FBG_Stage4);
            }
            if (health <= 0 && alive)
            {
                Death(0);
            }
    
        }
    
        public IEnumerator Stunned()
        {
            stunned = true;
            hitCounter = 0;
            anim.SetBool("Stunned", true);
    
            yield return new WaitForSeconds(6f);
            anim.SetBool("Stunned", false);
            stunned = false;
        }
    
        protected override void Death(float _destroyTimer)
        {
            ResetAllAttacks();
            alive = false;
            rb.velocity = new Vector2(rb.velocity.x, -25);
            anim.SetTrigger("Die");
            bloddTimer = 0.8f;
        }
        public void DestroyAfterDeath()
        {
            Destroy(gameObject);
        }
    }
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class Boss_Idle : StateMachineBehaviour
    {
        Rigidbody2D rb;
        // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
        override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            rb=animator.GetComponentInParent<Rigidbody2D>();
        }
    
        // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
        override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
           rb.velocity=Vector2.zero;
            RunToPlayer(animator);
    
            if(FinalBossGrog.Instance.attackCountDown <= 0)
            {
                FinalBossGrog.Instance.AttackHandler();
                FinalBossGrog.Instance.attackCountDown = Random.Range(FinalBossGrog.Instance.attackTimer-1, FinalBossGrog.Instance.attackTimer+1);
            }
    
            if (!FinalBossGrog.Instance.Grounded())
            {
                rb.velocity = new Vector2(rb.velocity.x, -25);
            }
        }
        void RunToPlayer(Animator animator)
        {
            if(Vector2.Distance(PlayerController.Instance.transform.position,rb.position)>= FinalBossGrog.Instance.attackRange)
            {
                animator.SetBool("Run", true);
            }
            else
            {
                return;
            }
        }
        // OnStateExit is called when a transition ends and the state machine finishes evaluating this state
        override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            
        }
      
    }
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class Boss_Run : StateMachineBehaviour
    {
        Rigidbody2D rb;
        // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
        override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            rb = animator.GetComponentInParent<Rigidbody2D>();
        }
    
        // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
        override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            TargetPlayerPosition(animator);
    
            if (FinalBossGrog.Instance.attackCountDown <= 0)
            {
                FinalBossGrog.Instance.AttackHandler();
                FinalBossGrog.Instance.attackCountDown = Random.Range(FinalBossGrog.Instance.attackTimer - 1, FinalBossGrog.Instance.attackTimer + 1);
            }
        }
    
        //OnStateExit is called when a transition ends and the state machine finishes evaluating this state
        override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            animator.SetBool("Run", false);
        }
    
        void TargetPlayerPosition(Animator animator)
        {
            if (FinalBossGrog.Instance.Grounded())
            {
                FinalBossGrog.Instance.Flip();
                Vector2 _target = new Vector2(PlayerController.Instance.transform.position.x, rb.position.y);
                Vector2 _newPos = Vector2.MoveTowards(rb.position, _target, FinalBossGrog.Instance.runSpeed * Time.fixedDeltaTime);
                
                rb.MovePosition(_newPos);
            }
            else
            {
                rb.velocity = new Vector2(rb.velocity.x, -25);
            }
    
            if(Vector2.Distance(PlayerController.Instance.transform.position, rb.position) <= FinalBossGrog.Instance.attackRange)
            {
                animator.SetBool("Run", false);
            }
            else
            {
                return;
            }
        }
    }
    
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class FBGEvents : MonoBehaviour
    {
        void SlashDamagePlayer()
        {
            if (PlayerController.Instance.transform.position.x > transform.position.x
               || PlayerController.Instance.transform.position.x < transform.position.x)
            {
                Hit(FinalBossGrog.Instance.SideAttackTransform, FinalBossGrog.Instance.SideAttackArea);
            }
            else if (PlayerController.Instance.transform.position.y > transform.position.y)
            {
                Hit(FinalBossGrog.Instance.UpAttackTransform, FinalBossGrog.Instance.UpAttackArea);
            }
            else if (PlayerController.Instance.transform.position.y < transform.position.y)
            {
                Hit(FinalBossGrog.Instance.DownAttackTransform, FinalBossGrog.Instance.DownAttackArea);
            }
        }
       void Hit(Transform _attackTransform, Vector2 _attackArea)
        {
            Collider2D[] _objectsToHit = Physics2D.OverlapBoxAll(_attackTransform.position, _attackArea, 0);
            for(int i=0; i<_objectsToHit.Length; i++)
            {
                if(_objectsToHit[i].GetComponent<PlayerController>() != null &&PlayerController.Instance.pState.alive)
                {
                    _objectsToHit[i].GetComponent<PlayerController>().TakeDamage(FinalBossGrog.Instance.damage);
                    if (PlayerController.Instance.pState.alive)
                    {
                        //PlayerController.Instance.HitStopTime(0, 5, 0.5f);
                    }
                }
            }
        }
        void Parrying()
        {
            FinalBossGrog.Instance.parrying = true;
        }
        void BendDownCheck()
        {
            if (FinalBossGrog.Instance.barrageAttack)
            {
                StartCoroutine(BarrageAttackTransition());
            }
            if (FinalBossGrog.Instance.outbreakAttack)
            {
                StartCoroutine(OutBreakAttackTransition());
            }
            if (FinalBossGrog.Instance.outbreakAttack)
            {
                FinalBossGrog.Instance.anim.SetTrigger("Bounce");
            }
        }
        void BarrageOrOutbreak()
        {
            if (FinalBossGrog.Instance.barrageAttack)
            {
                FinalBossGrog.Instance.StartCoroutine(FinalBossGrog.Instance.Barrage());
            }
            if (FinalBossGrog.Instance.outbreakAttack)
            {
                FinalBossGrog.Instance.StartCoroutine(FinalBossGrog.Instance.OutBreak());
            }
        }
        IEnumerator BarrageAttackTransition()
        {
            yield return new WaitForSeconds(1f);
            FinalBossGrog.Instance.anim.SetBool("Cast", true);
        }
    
        IEnumerator OutBreakAttackTransition()
        {
            yield return new WaitForSeconds(1f);
            FinalBossGrog.Instance.anim.SetBool("Cast", true);
        }
    
        void Bouncing()
        {
            FinalBossGrog.Instance.anim.SetTrigger("Bounce_1");
            FinalBossGrog.Instance.anim.ResetTrigger("Bounce");
        }
        private void DestroyAfterdeath()
        {
            SpawnBoss.Instance.IsNotTrigger();
            FinalBossGrog.Instance.DestroyAfterDeath();
            GestorPrograma.Instancia.FBGDefeated = true;
            SaveData.Instance.SaveBossData();
            SaveData.Instance.SavePlayerData();
        }
    }
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class Boss_Lunge : StateMachineBehaviour
    {
        Rigidbody2D rb;
        // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
        override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            rb = animator.GetComponentInParent<Rigidbody2D>();
        }
    
        // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
        override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            rb.gravityScale = 0;
            int _dir = FinalBossGrog.Instance.facingRight ? 1 : -1;
            rb.velocity = new Vector2(_dir * (FinalBossGrog.Instance.speed * 5), 0f);
    
            if (Vector2.Distance(PlayerController.Instance.transform.position, rb.position) <= FinalBossGrog.Instance.attackRange &&
                !FinalBossGrog.Instance.damagedPlayer)
            {
                PlayerController.Instance.TakeDamage(FinalBossGrog.Instance.damage);
                FinalBossGrog.Instance.damagedPlayer = true;
            }
        }
    
        // OnStateExit is called when a transition ends and the state machine finishes evaluating this state
        override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
         
        }
    
    }
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class Boss_Jump : StateMachineBehaviour
    {
        Rigidbody2D rb;
        // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
        override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            rb = animator.GetComponentInParent<Rigidbody2D>();
        }
    
        // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
        override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            DiveAttack();
        }
        void DiveAttack()
        {
            if (FinalBossGrog.Instance.diveAttack)
            {
                FinalBossGrog.Instance.Flip();
    
                Vector2 _newPos = Vector2.MoveTowards(rb.position, FinalBossGrog.Instance.moveToPosition, FinalBossGrog.Instance.speed * 3 * Time.fixedDeltaTime);
                rb.MovePosition(_newPos);
    
                float _distance = Vector2.Distance(rb.position, _newPos);
                if(_distance < 0.1f)
                {
                    FinalBossGrog.Instance.Dive();
                }
            }
        }
    
        // OnStateExit is called when a transition ends and the state machine finishes evaluating this state
        override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            
        }
    
    }
    
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class Boss_Dive : StateMachineBehaviour
    {
        Rigidbody2D rb;
        bool callOnce;
        // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
        override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            rb = animator.GetComponentInParent<Rigidbody2D>();
        }
    
        // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
        override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            FinalBossGrog.Instance.divingCollider.SetActive(true);
    
            if (FinalBossGrog.Instance.Grounded())
            {
                FinalBossGrog.Instance.divingCollider.SetActive(false);
                if (!callOnce)
                {
                    GameObject _impactParticle = Instantiate(FinalBossGrog.Instance.impactParticle, FinalBossGrog.Instance.groundCheckPoint.position, Quaternion.identity);
                    Destroy(_impactParticle, 3f);
                    FinalBossGrog.Instance.DivingPillar();
                    animator.SetBool("Dive", false);
                    FinalBossGrog.Instance.ResetAllAttacks();
                    callOnce = true;
                }            
               
            }
        }
    
        // OnStateExit is called when a transition ends and the state machine finishes evaluating this state
        override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            callOnce=false;
        }
    
    }
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class BarrageDarkBall : MonoBehaviour
    {
        [SerializeField] Vector2 startForceMinMax;
        [SerializeField] float turnSpeed = 0.5f;
    
        Rigidbody2D rb;
        // Start is called before the first frame update
        void Start()
        {
            rb=GetComponent<Rigidbody2D>();
            Destroy(gameObject, 4f);
            rb.AddForce(transform.right * Random.Range(startForceMinMax.x, startForceMinMax.y), ForceMode2D.Impulse);
        }
    
        // Update is called once per frame
        void Update()
        {
            var _dir=rb.velocity;
    
            if(_dir != Vector2.zero)
            {
                Vector3 _frontVector = Vector3.right;
    
                Quaternion _targetRotation = Quaternion.FromToRotation(_frontVector, _dir - (Vector2)transform.position);
                if (_dir.x > 0)
                {
                    transform.rotation = Quaternion.Lerp(transform.rotation, _targetRotation, turnSpeed);
                    transform.eulerAngles = new Vector3(transform.eulerAngles.x, 180, transform.eulerAngles.z);
                }
                else
                {
                    transform.rotation = Quaternion.Lerp(transform.rotation, _targetRotation, turnSpeed);
                }
            }
        }
        private void OnTriggerEnter2D(Collider2D collision)
        {
            if (collision.tag == "Player")
            {
                collision.GetComponent<PlayerController>().TakeDamage(FinalBossGrog.Instance.damage);
                Destroy(gameObject);
            }
        }
    }
    
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class Boss_BendDown : StateMachineBehaviour
    {
        Rigidbody2D rb;
        // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
        override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            rb = animator.GetComponentInParent<Rigidbody2D>();
            OutBreakAttack();
        }
    
        // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
        override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            
        }
        void OutBreakAttack()
        {
            if (FinalBossGrog.Instance.outbreakAttack)
            {
                Vector2 _newPos = Vector2.MoveTowards(rb.position, FinalBossGrog.Instance.moveToPosition, FinalBossGrog.Instance.speed * 1.5f * Time.fixedDeltaTime);
                rb.MovePosition(_newPos);
    
                float _distance = Vector2.Distance(rb.position, _newPos);
                if (_distance < 0.1f)
                {
                    FinalBossGrog.Instance.rb.constraints = RigidbodyConstraints2D.FreezePosition;
                }
            }
        }
        // OnStateExit is called when a transition ends and the state machine finishes evaluating this state
        override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            animator.ResetTrigger("BendDown");
        }
    
       
    }
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class Boss_Bounce_1 : StateMachineBehaviour
    {
        Rigidbody2D rb;
        // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
        override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            rb = animator.GetComponentInParent<Rigidbody2D>();
        }
    
        // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
        override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            if (FinalBossGrog.Instance.bounceAttack)
            {
                Vector2 _newPos = Vector2.MoveTowards(rb.position, FinalBossGrog.Instance.moveToPosition, FinalBossGrog.Instance.speed * Random.Range(2, 4) * Time.fixedDeltaTime);
                rb.MovePosition(_newPos);
    
                float _distance = Vector2.Distance(rb.position, _newPos);
                if (_distance < 0.1f)
                {
                    FinalBossGrog.Instance.CalculateTargetAngle();
                    animator.SetTrigger("Bounce_2");
                }
            }
        }
    
        // OnStateExit is called when a transition ends and the state machine finishes evaluating this state
        override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            animator.ResetTrigger("Bounce_1");
        }
    
        
    }
    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class Boss_Bounce_2 : StateMachineBehaviour
    {
        Rigidbody2D rb;
        bool callOnce;
        // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
        override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            rb = animator.GetComponentInParent<Rigidbody2D>();
        }
    
        // OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks
        override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            Vector2 _forceDirection = new Vector2(Mathf.Cos(Mathf.Deg2Rad * FinalBossGrog.Instance.rotationDirectionToTarget), Mathf.Sin(Mathf.Deg2Rad * FinalBossGrog.Instance.rotationDirectionToTarget));
            rb.AddForce(_forceDirection*3, ForceMode2D.Impulse);
    
            FinalBossGrog.Instance.divingCollider.SetActive(true);
    
            if (FinalBossGrog.Instance.Grounded())
            {
                FinalBossGrog.Instance.divingCollider.SetActive(false);
                if (!callOnce)
                {
                    FinalBossGrog.Instance.ResetAllAttacks();
                    FinalBossGrog.Instance.CheckBounce();
                    callOnce = true;
                }            
                animator.SetTrigger("Grounded");
            }
        }
    
        // OnStateExit is called when a transition ends and the state machine finishes evaluating this state
        override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
        {
            animator.ResetTrigger("Bounce_2");
            animator.ResetTrigger("Grounded");
            callOnce = false;
        }
    
    }

    The animation Set Up

    View post on imgur.com

    #15096
    Joseph Tang
    Moderator
    Helpful?
    Up
    0
    ::

    Please refer to this post to see if it solves your Boss Issues, particularly point [1]

    [Part 10] Article Changes, Common Issues & Bugfixes

    As for the diving pillars, can you check that the position is NOT recorded in your animation as done so in this other post:

    [part 10] boss problems

    #15098
    Mr Thinker
    Participant
    Helpful?
    Up
    0
    ::

    I’ve already done the fixes proposed in the post but it seems that nothing changed in the question, altough to the Pillars he won’t get to the Ground now to even spawn them.

    #15099
    Joseph Tang
    Moderator
    Helpful?
    Up
    0
    ::

    Alright then. Sorry but, peferably, could you send a video of how your bug looks like and the animation window + boss inspector, for me to understand your situation fully? Also, could you check for any error messages in the console while testing.

    You could also try adding the rb velocity line into Boss_dive and others to ensure the boss falls.

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

Go to Login Page →


Advertisement below: