bool rotate(Transform transform, Vector3 diff, float rot_speed) { Vector3 rot; Vector3 foward = diff.normalized; float angle = rot_speed * Time.deltaTime; if (in_range(transform.forward, foward, angle, out rot) == false) { RotateLogic.Rotate(transform, foward, angle); return(true); } return(false); }
/// <summary> /// get rotate info /// </summary> /// <param name="transform"></param> /// <param name="diff"></param> /// <param name="angle_range"></param> /// <param name="over_rate"></param> /// <param name="is_over"></param> /// <returns></returns> int rotate(Transform transform, Vector3 diff, float angle_range, float over_rate, out bool is_over) { is_over = false; var rot = RotateLogic.GetAngle(transform.up, transform.forward, diff.normalized); var sqrtRot = rot * rot; var sqrtRange = angle_range * angle_range; if (sqrtRot < sqrtRange) { return(0); } is_over = sqrtRot > sqrtRange * over_rate * over_rate; return(rot < 0 ? -1 : 1); }