public float GetFaceAngle() { return(enemy.GetFacingAngle()); }
void Update() { wait_timer += Time.deltaTime; move_dir = Vector3.right * Mathf.Sign(transform.localScale.x); //If still in starting path if (!waiting && !HasFallen() && path_list.Count > 0) { //Move Vector3 targ = path_list[current_path]; enemy.MoveTo(targ, speed_mult); move_dir = Vector3.right * Mathf.Sign((targ - transform.position).x); //Check if reached target Vector3 dist_vect = (targ - transform.position); dist_vect.z = 0f; if (dist_vect.magnitude < 0.1f) { waiting = true; wait_timer = 0f; } //Check if obstacle ahead bool fronted = enemy.CheckFronted(dist_vect.normalized); if (fronted && wait_timer > 2f) { RewindPath(); wait_timer = 0f; } } //If can't reach starting path anymore if (!waiting && HasFallen()) { //Move Vector3 mdir = Vector3.right * (path_rewind ? -2f : 2f); Vector3 targ = transform.position + mdir; enemy.MoveTo(targ, speed_mult); enemy.FaceToward(targ); move_dir = Vector3.right * Mathf.Sign((targ - transform.position).x); //Check if obstacle ahead Vector3 dist_vect = (targ - transform.position); bool fronted = enemy.CheckFronted(dist_vect.normalized); if (fronted && wait_timer > 2f) { path_rewind = !path_rewind; wait_timer = 0f; } } if (waiting) { //Wait a bit if (wait_timer > wait_time) { GoToNextPath(); waiting = false; wait_timer = 0f; } } //Angle pause_timer += Time.deltaTime; if (pause_timer > pause_duration) { float angle_target = angle_rewind ? angle_min : angle_max; current_angle = Mathf.MoveTowards(current_angle, angle_target, angle_speed * Time.deltaTime); face_dir = new Vector3(Mathf.Cos(current_angle * Mathf.Deg2Rad), Mathf.Sin(current_angle * Mathf.Deg2Rad), 0f); face_dir = new Vector3(Mathf.Sign(move_dir.x) * face_dir.x, face_dir.y, 0f); } enemy.FaceToward(transform.position + face_dir * 2f); if (!angle_rewind && enemy.GetFacingAngle() > angle_max) { angle_rewind = true; pause_timer = 0f; } if (angle_rewind && enemy.GetFacingAngle() < angle_min) { angle_rewind = false; pause_timer = 0f; } }