Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Passing small values through Vectors

Hey there. I am unable to pass very small values through a Vector but I need to be able to pass that small a value for Texture mapping. I am trying to create a voxel game and so I need to define Textures of each block face for which I need texture Mapping. This is easy for small amounts of items. I have a 2048 by 2048 pictures of a few textures and each of the pictures within is a 16 * 16 but when I divide 16 in float by 2048 and convert it into Texture, it becomes 0.

Is there any way of overcoming this problem rather than decreasing the size of the texture atlas?

Best Answer

  • SanderSander Member
    edited May 2020 Accepted Answer

    I found the error! There is nothing wrong with what you're doing, but when you write to the console it rounds the number to a single decimal point, in this case it would simply be rounded to 0. So what you'll want to write instead is this:

    Debug.Log(new Vector2(a, 0).ToString("F5"));

    The F5 determines how many decimals you want to display.

    Hope this helps :D


  • How do you do this division in your code? You are probably missing a cast somewhere to float.

  • I even set a variable to 16 / 2048.0f and it printed it correctly as 0.015625 but when I made a Vector2 with that same variable, it just set it to 0

  • SanderSander Member

    Can you try to show us the code?

  • XeramianXeramian Member
    edited May 2020

    Thanks a lot.

Sign In or Register to comment.