void FixedUpdate() { onGround = CheckGrounded(); if (AgentRigidbody.velocity.y < 0) //if player character is falling and not on a moving platform { AgentAnimator.SetBool("Falling", true); //play falling animation. This can't be a trigger because we are unsure how far the player character is falling and so the animation has to be played } // until explicitly told to stop. (i.e boolean is false again) HandleLayers(); //prioritise getting powerup but ignore if player is closer to it //otherwise melee attack player. UpdateImmunity(); myHealthBar.UpdateHealth(hitpoints, 800f); UpdatePowerUp(); if (!MeleePowerUp && (!powerupSpriteRenderer.enabled || playerObstructingPowerup()) && !PlayerMeleeRange()) { if (!(activeState is RangedAttackState)) { SetState(new RangedAttackState()); } } else if (powerupSpriteRenderer.enabled && !playerObstructingPowerup() && PowerUpReachable()) { if (!(activeState is SeekPowerState)) { SetState(new SeekPowerState()); } } else if (!(activeState is MeleeAttackState)) { SetState(new MeleeAttackState()); } activeState.Act(); }
private bool CheckGrounded() { if (AgentRigidbody.velocity.y <= 0) //if we are not jumping { foreach (Transform point in groundPoints) { Collider2D[] colliders = Physics2D.OverlapCircleAll(point.position, groundCollideRadius, whatIsGround); //create colliders that check for whatIsGround (currently set to everything) //within groundCollideRadius (set in unity) of point.position (The PC's feet and a centre point between them) for (int i = 0; i < colliders.Length; i++) { if (colliders[i].gameObject != gameObject) //if the colliders are colliding with a gameObject that is not the player (i.e. the ground) { AgentAnimator.ResetTrigger("Jump"); AgentAnimator.SetBool("Falling", false); // we have finished falling (or we never were) so tell Unity we don't need to play the animation return(true); //then we are on the ground } } } } return(false); //otherwise if colliders are only colliding with the player character, we must not be on the ground }
// Update is called once per frame void FixedUpdate() { if (Alive()) { UpdateHide(); if (!(activeState is RangedAttackState)) { AgentAnimator.SetBool("Shooting", false); } PlayerNearby = LookForPlayer(); if (!hiding) { if (!Patrol && !PlayerNearby && !(activeState is IdleState)) { SetState(new IdleState()); } else if (Patrol && !PlayerNearby && !(activeState is PatrolState)) { SetState(new PatrolState()); } } if (PlayerNearby && !IsPlayerReachable() && !(activeState is HideState)) { SetState(new HideState()); hiding = true; } else if (IsPlayerReachable() && !(activeState is RangedAttackState)) { SetState(new RangedAttackState()); hiding = false; } activeState.Act(); } }
void FixedUpdate() { onGround = CheckGrounded(); if (AgentRigidbody.velocity.y < 0) //if player character is falling and not on a moving platform { AgentAnimator.SetBool("Falling", true); //play falling animation. This can't be a trigger because we are unsure how far the player character is falling and so the animation has to be played } // until explicitly told to stop. (i.e boolean is false again) HandleLayers(); myHealthBar.UpdateHealth(hitpoints, 400f); if (hitpoints < 300 && !SecondPhaseReached) { FirstPhase = false; SecondPhase = true; } else if (hitpoints < 200 && !ThirdPhaseReached) { ThirdPhase = true; } else if (hitpoints < 100 && !FourthPhaseReached) { FourthPhase = true; } else if (hitpoints <= 0) { if (!(activeState is PhaseChangeState)) { SetState(new PhaseChangeState()); } activeState.Act(); exitDoor.OpenDoor(); } if (Alive()) { if (FirstPhase) { PlayerNearby = LookForPlayer(); if (SecondPhase || ThirdPhase || FourthPhase) { if (!(activeState is PhaseChangeState)) { SetState(new PhaseChangeState()); } } else if (!Patrol && !PlayerNearby && !(activeState is IdleState)) { SetState(new IdleState()); //can possibly remove idle and patrol states here. } else if (Patrol && !PlayerNearby && !(activeState is PatrolState)) { SetState(new PatrolState()); } else if (PlayerMeleeRange() && !(activeState is MeleeAttackState)) { SetState(new MeleeAttackState()); } else if (PlayerNearby && !PlayerMeleeRange() && !(activeState is ChaseState)) { SetState(new ChaseState()); } } else { if (SecondPhase || ThirdPhase || FourthPhase) { Debug.Log("SecondPhase : " + SecondPhase); Debug.Log("ThirdPhase : " + ThirdPhase); Debug.Log("FourthPhase : " + FourthPhase); if (!(activeState is PhaseChangeState)) { SetState(new PhaseChangeState()); } } else if (PlayerMeleeRange() && !(activeState is MeleeAttackState)) { AgentAnimator.SetBool("Throwing", false); SetState(new MeleeAttackState()); } else if (!(activeState is RangedAttackState)) { SetState(new RangedAttackState()); } } activeState.Act(); } }