public bool IsDead() { if (destruct) { return(destruct.IsDead()); } return(false); }
private void SlowUpdate() { if (destruct != null && auto_destroy && !destruct.IsDead() && !building_mode) { if (!CheckValidFloorBuilt() || !CheckIfFlatGround()) { destruct.Kill(); } } }
void Update() { Vector3 dir = TheCamera.Get().GetFacingFront(); transform.rotation = Quaternion.LookRotation(dir, Vector3.up); if (target == null || target.IsDead()) { Destroy(gameObject); } else { fill.fillAmount = target.hp / (float)target.GetMaxHP(); canvas_group.alpha = fill.fillAmount < 0.999f ? 1f : 0f; } }
private void Update() { if (TheGame.Get().IsPaused()) { return; } if (state == PetState.Dead) { return; } state_timer += Time.deltaTime; //States if (state == PetState.Idle) { if (state_timer > 2f) { if (HasFollowTarget()) { ChangeState(PetState.Follow); } else { DetectPlayer(); } } } if (state == PetState.Follow) { if (!IsMoving() && PlayerIsFar(follow_range)) { character.Follow(player_target.gameObject); } DetectAction(); } if (state == PetState.Dig) { if (action_target == null) { StopAction(); return; } Vector3 dir = action_target.transform.position - transform.position; if (dir.magnitude < 1f) { character.Stop(); character.FaceTorward(action_target.transform.position); if (animator != null) { animator.SetTrigger("Dig"); } StartCoroutine(DigRoutine()); } if (state_timer > 10f) { StopAction(); } } if (state == PetState.Attack) { if (attack_target == null || attack_target.IsDead()) { StopAction(); return; } Vector3 targ_dir = attack_target.transform.position - transform.position; if (!force_action && state_timer > action_duration) { if (targ_dir.magnitude > detect_range || PlayerIsFar(detect_range * 2f)) { StopAction(); } } if (targ_dir.y > 10f) { StopAction(); //Bird too high } } if (state == PetState.Pet) { if (state_timer > 2f) { if (HasFollowTarget()) { ChangeState(PetState.Follow); } else { ChangeState(PetState.Idle); } } } if (state == PetState.MoveTo) { if (character.HasReachedMoveTarget()) { StopAction(); } } if (animator != null) { animator.SetBool("Move", IsMoving()); } }
public bool IsDead() { return(destruct.IsDead()); }
void Update() { if (TheGame.Get().IsPaused()) { return; } if (IsDead()) { return; } if (buildable && buildable.IsBuilding()) { return; } attack_timer += Time.deltaTime; move_timer += Time.deltaTime; navmesh_timer += Time.deltaTime; ground_refesh_timer += Time.deltaTime; //Detect obstacles and ground if (ground_refesh_timer > ground_refresh_rate) { ground_refesh_timer = Random.Range(-0.02f, 0.02f); DetectGrounded(); DetectFronted(); } //Save position PlayerData.Get().SetCharacterPosition(GetUID(), SceneNav.GetCurrentScene(), transform.position, transform.rotation); //Stop moving if (is_moving && !HasTarget() && HasReachedMoveTarget(moving_threshold * 2f)) { Stop(); } //Stop attacking if (is_attacking && !HasAttackTarget()) { Stop(); } //Following if (target != null) { Vector3 targ_dir = (target.transform.position - transform.position); targ_dir.y = 0f; if (is_moving && !is_attacking) { if (is_escaping) { Vector3 targ_pos = transform.position - targ_dir.normalized * 4f; move_target = targ_pos; } else { move_target = target.transform.position; //Stop following if ((attack_target != null || attack_player != null) && targ_dir.magnitude < GetAttackTargetHitRange() * 0.8f) { move_target = transform.position; is_moving = false; } //Stop following if (attack_target == null && attack_player == null && HasReachedMoveTarget(follow_distance)) { move_target = transform.position; is_moving = false; } } } //Start following again if (!is_moving && !is_attacking) { if (targ_dir.magnitude > GetAttackTargetHitRange()) { is_moving = true; } } } //Attacking if (HasAttackTarget() && attack_enabled) { if (!is_attacking) { if (attack_timer > attack_cooldown) { Vector3 targ_dir = (target.transform.position - transform.position); targ_dir.y = 0f; if (targ_dir.magnitude < GetAttackTargetHitRange()) { is_attacking = true; is_moving = false; attack_hit = false; attack_timer = 0f; if (onAttack != null) { onAttack.Invoke(); } } } } if (is_attacking) { move_target = transform.position; move_target_avoid = transform.position; FaceTorward(target.transform.position); if (!attack_hit && attack_timer > attack_windup) { float range = (target.transform.position - transform.position).magnitude; if (range < GetAttackTargetHitRange()) { if (attack_target != null) { attack_target.TakeDamage(this, attack_damage); } if (attack_player != null) { attack_player.Combat.TakeDamage(attack_damage); } } attack_hit = true; if (selectable.IsNearCamera(20f)) { TheAudio.Get().PlaySFX("character", attack_audio); } } if (attack_timer > attack_duration) { is_attacking = false; attack_timer = 0f; is_moving = true; if (attack_target != null) { Attack(attack_target); } if (attack_player != null) { Attack(attack_player); } } } if (attack_target != null && attack_target.IsDead()) { Stop(); } if (attack_player != null && attack_player.IsDead()) { Stop(); } } //Add an offset to escape path when fronted if (avoid_obstacles && !direct_move) { if (is_fronted_left && !is_fronted_right) { avoid_side = 1f; } if (is_fronted_right && !is_fronted_left) { avoid_side = -1f; } //When fronted on all sides, use target to influence which side to go if (is_fronted_center && is_fronted_left && is_fronted_right && target) { Vector3 dir = target.transform.position - transform.position; dir = dir * (is_escaping ? -1f : 1f); float dot = Vector3.Dot(dir.normalized, transform.right); if (Mathf.Abs(dot) > 0.5f) { avoid_side = Mathf.Sign(dot); } } float angle = avoid_side * 90f; float far_val = is_fronted ? 1f - (front_dist / destruct.hit_range) : Mathf.Abs(angle) / 90f; //1f = close, 0f = far float angle_speed = far_val * 150f + 50f; avoid_angle = Mathf.MoveTowards(avoid_angle, is_fronted ? angle : 0f, angle_speed * Time.deltaTime); } }