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 /
  • Help Room /
This question was closed Feb 02, 2016 at 04:37 PM by Hydropulse17 for the following reason:

The question is answered.

avatar image
0
Question by Hydropulse17 · Feb 02, 2016 at 07:23 AM · fbxmodelsmeshfilterlocalscale

Possible to redefine the size of a model without scaling or using a 3D modeling program?

So I have three downloaded models that were free for all extended uses. My game object's mesh filter is changed to one of the three models at random on Start. This is done so that there is some randomness to what the objects look like in my game. The object is also assigned one of three options in an enumerator at random, small, medium, and large. I used a switch, where each case is one of the 3 options. The scale is set to 1,1,1 for small, 2,2,2 for medium, and 4,4,4 for large.

Everything works perfectly so that there different sizes of the object, and even several instances of the object that are the same size can be different models. The only problem is that one of the three models is 1.5 times smaller than the other two. The fix seemed easy enough to do with code, I didn't expect to have a problem, but I tried all kinds of things, all of which seemed like they would work but nothing did. I decided that the easiest fix would be to just import the fbx file into Maya, and export it back into Unity the proper size, but for some reason Maya didn't recognize the file. I downloaded Blender to try and change it, but it told me the file was an old version and that Blender couldn't read it.

So I can't figure out how to fix the scale of every object assigned mesh1 in code, and I can't fix the size of the model itself. Is there a way to change the model in code, not through scale, but by redefining the size of the model at 1,1,1 scale?

↑▲▲▲MAIN QUESTION▲▲▲↑

If that's not possible, and you'd care to try and succeed where I have failed with the scale, you can look at my script, but it's kind of big for a forum question I think, and I wouldn't expect any one to put that much effort into solving my problem. Here it is though, I'll try to add some comments to make interpreting it easier...

     private int meshRandInt;
 
     public float meshRand;
     public float sizeRand;
     public float sizeMult;
 
     public Mesh boulder1; //this one is too small
     public Mesh boulder2;
     public Mesh boulder3;
 
     private bool meshLoaded;
     private bool sizeChosen;
 
     public AsteroidSize asteroidSize;
 
     public enum AsteroidSize
     {
         Small,
         Medium,
         Large
     }
 
     void Start () {
   
         meshRand = (Random.Range(0f, 3f));
         meshRandInt = Mathf.FloorToInt(meshRand); //Gives a value, 0,1 or 2 for the loadMesh method
 
         sizeRand = (Random.Range(0f,10f));//for choosing which size the object will be
     }
 
     void Update ()
     {
         switch (asteroidSize) //changes the scale of the object based on AsteroidSize(NOT BASED ON                                     //MESH, but boulder1 mesh needs a 2.5 scale base to be the correct size)
         {
             case AsteroidSize.Small:
                 sizeMult = 1;
                 transform.localScale = new Vector3(1, 1, 1) * sizeMult;
                 break;
             case AsteroidSize.Medium:
                 sizeMult = 2;
                 transform.localScale = new Vector3(1, 1, 1) * sizeMult;
                 break;
             case AsteroidSize.Large:
                 sizeMult = 4;
                 transform.localScale = new Vector3(1, 1, 1) * sizeMult;
                 break;
         }
 
         if (!sizeChosen) //Assigns at random the AsteroidSize
         {
             if (sizeRand >= 0 && sizeRand <= 5)//0-5 = small %50 chance
             {
                 asteroidSize = AsteroidSize.Small;
                 sizeChosen = true;
             } else if (sizeRand > 5 && sizeRand <= 8) // %30 for medium
             {
                 asteroidSize = AsteroidSize.Medium;
                 sizeChosen = true;
             } else if (sizeRand > 8) //%20 for Large
             {
                 asteroidSize = AsteroidSize.Large;
                 sizeChosen = true;
             }
         }
 
         LoadMesh();
 
     }
 
     public void LoadMesh() //Assigns different meshes depending on the value of meshRandInt
     {
         if (meshRandInt == 0)
         {
             GetComponent<MeshFilter>().mesh = boulder1;
 
             if (!meshLoaded)
             {
                 GetComponent<MeshCollider>().sharedMesh = null;
                 GetComponent<MeshCollider>().sharedMesh = GetComponent<MeshFilter>().mesh;
                 meshLoaded = true;
 
             }
         }
 
         if (meshRandInt == 1)
         {
             GetComponent<MeshFilter>().mesh = boulder2;
 
             if (!meshLoaded)
             {
                 GetComponent<MeshCollider>().sharedMesh = null;
                 GetComponent<MeshCollider>().sharedMesh = GetComponent<MeshFilter>().mesh;
                 meshLoaded = true;
             }
         }
 
         if (meshRandInt == 2)
         {
             GetComponent<MeshFilter>().mesh = boulder3;
 
             if (!meshLoaded)
             {
                 GetComponent<MeshCollider>().sharedMesh = null;
                 GetComponent<MeshCollider>().sharedMesh = GetComponent<MeshFilter>().mesh;
                 meshLoaded = true;
             }
         }
     }

I tried wrapping the transform.local size statements from the switch in an if statement that first checks if the mesh filter is set to boulder1, if it is then it sets the scale to 2.5,2.5,2.5 and multiplies it by the size multiplier, if it isn't boulder1, then it sets the scale to 1,1,1 and multiplies it, but that didn't work. It still seems like it would to me. IDK, but I need to figure this out, because if a large size asteroid with the boulder1 mesh is destroyed, two medium sized asteroids will be instantiated and there will be more mass(in the eyes of the player) than there was before and it won't make sense. Now that I think about it, I could leave out boulder1 and just use the other two, but I'd rather not.

Comment
Add comment · Show 2
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 saschandroid · Feb 02, 2016 at 08:40 AM 1
Share

Have you tried to set the scale of you model 1.5 (bigger than the others) in the import settings?

avatar image Hydropulse17 saschandroid · Feb 02, 2016 at 04:36 PM 0
Share

I gotta say, I'm feeling pretty stupid right now... So much effort into fixing this tiny issue, and that was the solution the entire time. I didn't know you could do that, I've never had a reason to.

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

34 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity problems with .FBX models,Unity3D problems with FBX model 0 Answers

Anyone know why avatar seems blocky 0 Answers

Unity mesh collider incorrect position 6 Answers

AssetPostprocessor and reimporting only some fbx 0 Answers

.c4d file does not carry the animation into unity 0 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