private void Update() { float angleCamUnit = Vector3.Angle(trCamera.forward, trUnit.forward); AvatarDirection avatar = avatarConfig.GetAvatarByAngle(angleCamUnit); bool isFlip = false; if (avatar.IsCanFlip) { Vector3 cross = Vector3.Cross(trCamera.forward, trUnit.forward); isFlip = cross.y < 0; } rendererModel.sprite = avatar.Idle; rendererModel.flipX = isFlip; }
public AvatarDirection GetAvatarByAngle(float directionAngleDeg) { float smallestLengVel = float.MaxValue; AvatarDirection best = avatarDirections[0]; foreach (var item in avatarDirections) { float angleDiff = Mathf.Abs(Mathf.DeltaAngle(directionAngleDeg, item.AngleDeg)); if (angleDiff < smallestLengVel) { best = item; smallestLengVel = angleDiff; } } return(best); }