void Update() { fwd = target.position - transform.position; dest = transform.position + transform.forward * lookRadius / 1.5f; dist = transform.position + transform.forward * lookRadius * 1.7f; //agent.velocity = 3.5f; float distance = Vector3.Distance(target.position, dest); float distance2 = Vector3.Distance(target.position, transform.position); if (!sleeping) { if (distance2 < 30f) { if (!sleeping) { pcont.CheckEnemies(); } } if (distance <= lookRadius) { //FaceTarget(); targetHit = Physics.Raycast(transform.position, fwd, out tHit, lookRadius * 1.7f); if (targetHit) { if (tHit.transform == target.transform) { //agent.SetDestination(target.position); redEye.AttackEye(); isAttacking = true; agent.speed = 7f; xSpeed = 1f; if (momDino != null) { momDino.SetDestination(target); } else { patrol.SetAttack(); patrol.AttackNextPoint(target.position); SetDestination(target); } } } if (distance2 <= agent.stoppingDistance) { if (targetStats != null) { animator.SetBool("attack", true); combat.Attack(targetStats); } FaceTarget(); } else { animator.SetBool("attack", false); } } else { if (isAttacking) { patrol.NotAttack(); redEye.NotAttackEye(); isAttacking = false; } agent.speed = 1.28f; xSpeed = 0.5f; } // Debug.Log("vel " + agent.velocity.magnitude); float speedPercent = agent.velocity.magnitude / agent.speed * xSpeed; animator.SetFloat("speedPercent", speedPercent, locomotionAnimationSmoothTime, Time.deltaTime); } else { sleepTime += .01f; isAttacking = false; animator.SetBool("attack", false); animator.SetBool("sleeping", true); if (sleepTime > timeToSleep) { animator.SetBool("sleeping", false); sleeping = false; sleepTime = 0; myStats.Born(); agent.isStopped = false; } } }
void Update() { if (isAttacking) { if (!agent.hasPath) { //patrol.GotoNextPoint(); patrol.AttackNextPoint(target.position); } attackTime -= 0.15f; if (attackTime <= 0f) { NotAttack(); } hidingEye.fillAmount = attackTime / maxTime; //Debug.Log(attackTime / maxTime); } else { // attackTime = 0f; } //fwd = transform.TransformDirection(Vector3.forward) * lookRadius * 1.7f; fwd = target.position - transform.position; dest = transform.position + transform.forward * lookRadius / 1.5f; dist = transform.position + transform.forward * lookRadius * 1.7f; float distance = Vector3.Distance(target.position, dest); float distance2 = Vector3.Distance(target.position, transform.position); if (distance <= lookRadius || isAttacking) { //Idle(); //FaceTarget(); //agent.SetDestination(agent.destination); bool hiding = playerController.CheckHiding(); if (!hiding) { targetHit = Physics.Raycast(transform.position, fwd, out tHit, lookRadius * 1.7f); //targetHit = Physics.BoxCast(transform.position, transform.localScale*3, fwd, out tHit, transform.rotation, lookRadius * 1.7f); if (targetHit) { // Debug.Log(tHit.transform.name); if (tHit.transform == target.transform) { MomAttack(); if (notSee >= 5f) { patrol.Attack2(); notSee = 0f; } } else { notSee += 0.1f; isHidden = true; //Debug.Log(tHit.transform.name); //isAttacking = false; } } if (distance2 <= agent.stoppingDistance) { if (targetStats != null) { animator.SetBool("eating", true); combat.Attack(targetStats); } FaceTarget(); } else { animator.SetBool("eating", false); } if (isAttacking) { if (attackTime <= 0f) { patrol.AttackNextPoint(target.position); // attackTime = 100f; } //agent.SetDestination(target.position); } if (notSee >= 100f) { notSee = 0f; NotAttack(); patrol.NotAttack(); patrol.GotoNextPoint(); } } else if (distance2 <= agent.stoppingDistance) { MomAttack(); /* * notSee = 0f; * if (isAttacking) * { * if (attackTime <= 30f) * { * isAttacking = false; * NotAttack(); * patrol.AttackNextPoint(target.position); * attackTime = 0f; * } * else if (attackTime == 0f && notSee == 0f) * { * patrol.NotAttack(); * } * * //agent.SetDestination(target.position); * } */ } } }