Common Conversions

First, transform.position doesn’t ‘convert’ into a Vector3, it is a Vector3.

I’m not 100% sure what you are asking but I’ll give it a stab. What I find often is:

  • Vector3Vector2Vector3
    You can cast it both ways. Casting Vector3 to Vector2 will lose the z
  • QuaternionVector3Quaternion
    You can use Quaternion.eulerAngles to get a Vector3 as it appears in the inspector’s rotation bits. The vector will hold the degrees for each axis.
    You can also get a Quaternion from Vector3 with Quaternion.Euler(Vector3). Note that converting it to Quaternion applies the axis rotations in a specific order (first z, then x, then y) and that is important because it can affect the final rotation. Although I’ve never had to worry about this, it’s important to know this in case you do run into issues
  • floatint
    I mention this one because there are 3 different methods in Unity and each one has it’s own use to consider. Actually, there are others but these are specific and can be the answer to you hitting an enemy with 1 health for 1 damage and it not dying.
    We have Mathf.RoundToInt(float) which will just round the decimal like we kinda learned in school. If the fraction is less than 0.5 it will round down, if it’s more than 0.5 it will round up and if it is exactly 0.5 it will round to the even integer. That is; 1.5 will become 2 and 2.5 will also become 2.
    Then there’s Mathf.FloorToInt(float) which will always round down (1.1 will become 1 and 1.9 will also become 1), and
    Mathf.CeilToInt(float) which will always round up (1.9 will become 2 and 1.1 will also become 2).
    These are easy to remember because the ‘floor’ is down and the ‘ceiling’ (‘Ceil’ is short for ceiling) is up.

That’s about it, though. I can’t think of any other conversions right now.

1 Like