Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by waterdog · May 01, 2016 at 07:25 AM · meshmathfloat

Why can't I get a floating point value here?...

Possibly the stupidest question I've asked here yet, but, I seem only able to get the integer part back from what I'm pretty sure is a float calculation!. I'm having flashbacks to FORTRAN and implicitly typed variable names...;^) I've tried a bunch of crazy stuff to get a float as you can see in the included code segment but the Debug.Log definitely only shows integer values, (which really messes up mesh alignments!).

 Bathys = new GameObject[x_meshes,z_meshes];
     float fi = 0;
     float fj = 0;
     for (int i=0; i<x_meshes; i++) {
         for (int j=0; j<z_meshes; j++){

             // Generate named gameobjects and make them children of bathyBoss object.
             // It isn't strictly necessary to provide names for the GameObjects
             // generated by the script, but, they show up in the hierarcy at run
             // time so they look cleaner, and being able to find by name helps in 
             // clean up for regenerations and such.

             string goname = System.String.Format("Bathy_{0}{1}",i,j);
             Bathys[i,j] = new GameObject(goname);                     
             Bathys[i,j].transform.parent = bathyBoss.transform;    
 
             Bathys[i,j].AddComponent<MeshRenderer>();
             Bathys[i,j].AddComponent<MeshFilter>();
             Bathys[i,j].AddComponent<ShowMeshVertices>();

             Mesh bathy = new Mesh();                            
             bathy.vertices = GenVertices ();
             Bathys[i,j].GetComponent<MeshFilter>().sharedMesh = bathy;  

             // add a mesh collider for flythrough terrain avoidance
             MeshCollider mshcol = Bathys[i,j].AddComponent(typeof(MeshCollider)) as MeshCollider;
             mshcol.sharedMesh = bathy;

             // position mesh's gameobject for correct overlap

             /*
                     ij
     
                         10 | 11
                                   ---+---  
                                 00 | 01

                            */


         //    float x_off = ((float)i)*x_cells;  
         //    float z_off = ((float)j)*z_cells;
             float x_off = fi*(float)x_cells;  // need some work for other than 1.0 sizes 
             float z_off = fj*(float)z_cells;

             // WHAT IN THE...?!! CAN'T MAKE A FLOAT HERE...

             Debug.Log("x_off " + i  + " = " + x_off);
             Debug.Log("z_off " + j  + " = " + z_off);

             Bathys[i,j].transform.position = new Vector3((float)x_off,0f,(float)z_off);
             fj++;
         }
         fi++;
         fj=0;
     }
 }


Comment
Add comment · Show 5
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image MD_Reptile · May 01, 2016 at 07:29 AM 1
Share

I don't totally understand the question. I see that your adding one to fj, and fi, and your multiplying them by x_cells and z_cells... what is supposed to happen? Whats the expected outcome? What happens? What should the information that debug log contains show you?

Just looking at it, seems to me your multiplying a whole number, by a whole number (float or not) and the result is... a whole number? What is the problem though? If you had typed "Debug.Log(x_off + 0.25487f);" you will end up with with a non-whole number...

Another thing is, you don't need to cast a float as a float (like "(float)x_off" ) because it is already a float.

avatar image waterdog MD_Reptile · May 02, 2016 at 05:14 PM 0
Share

Hi $$anonymous$$D_Reptile, I'm aware you shouldn't have to cast x_off to a float, but, I've been trying everything I can do to get a float result...;^) The problem is I get integer results here that cause issues elsewhere in the code when they get used and need to be floats so other results don't become ints.

avatar image tanoshimi waterdog · May 02, 2016 at 06:14 PM 0
Share

I agree with @$$anonymous$$D_reptile - I can't see the problem here. You know that by the time you're seeing the result of Debug.Log, it's not a float or an int? It's a string.... are you just being puzzled by the way it is displayed in the console window?

Show more comments
avatar image tanoshimi · May 01, 2016 at 07:41 AM 0
Share

What value are x_cells and z_cells? If they're whole numbers, I see no issue here. What were you expecting to print? What actually printed?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Outliver · May 02, 2016 at 06:26 PM

Try to set

 float fi = 0f;

instead of

 float fi = 0;

And try

 fi += 1.0f;

instead of

 fi++

Not sure but that could fix it.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Maths issue + Null reference error? -1 Answers

UV's not reapplying correctly from deserialization 0 Answers

Get mesh intersection points with arbitrary plane/disc 1 Answer

[RESOLVED] Raycast - Calculate Angular Difference from Object 3 Answers

How to scale Mesh.bindPose correctly 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges