Search Unity

Question Calculate angular height of TMP_Text

Discussion in 'UGUI & TextMesh Pro' started by OliHCI, Aug 18, 2023.

  1. OliHCI

    OliHCI

    Joined:
    May 22, 2023
    Posts:
    1
    Hi there,

    I am working on an assignment for university in which I have to build a 3D-UI in unity.
    I have to find a solution to display the text with an ideal fontsize which covers about 2.5deg angular height in respect to the users position.

    When I try to calculate the angular height of my chosen fontsize by using the equation below, the results seem implausible to me:
    Code (CSharp):
    1. [SerializeField] private float metersToPtRatio = 2834.6457f;
    2. float measuredAngularHeight = Mathf.Rad2Deg * Mathf.Atan(t.fontSize / (distanceToMainPlayerCamera*metersToPtRatio));
    For example with a distance of 3m, i have to increase the fontsize up to 360pt to get an angular height of ~2.5deg. From my visual perception a fontsize of 36pt covers about 2,5deg, so my equation seems to have a wrong factor *10.

    I've read that in unity distances are measured in meters, so I should be able to convert fontsizes/distances by using a conversion factor of ~2834?!

    Has anyone an idea? Aside from the text's scale factor, is there another factor which affects the fontsize?

    Thanks in adavance!
    Greets
    Oli