Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 altair2020 · May 26, 2013 at 01:25 PM · scalesizesphereclonecopy

How to copy the real size of another sphere gameobject

Hi everyone, i cannot work this out...

I have many spheres in my game, i have a sphere at my cursor and i want to make this sphere match the same size as another sphere in my game when it collides with them.

I have made my spheres in blender3d and they are all scaled to the same scale ( 1, 1, 1 ) in the editor, but visibly they are different in size. So I cannot easily just copy the scale over.

How do i find the true size/scale of another sphere gameobject and then resize it to match its collided sphere object?

this is what i have so far but its not working...

 void OnTriggerEnter(Collider other) {
         Debug.Log ("Trigger collidied with: "+ other.gameObject.name.ToString());
         
         if ( other.gameObject.tag == "takesize")
         {
         
             this.transform.localScale = new Vector3 (other.transform.localScale.x,this.transform.localScale.y ,this.transform.localScale.z);
             
 
             
         }
         
     }


Thanks for your help!

J.

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by robertbu · May 26, 2013 at 02:31 PM

A couple of ideas come to mind. First you can use Bounds.extents of the Mesh.bounds. These values give you the half-width, half-height, and half-depth of the object. You can then calculate the relative size. Here is a bit of code that outputs the extents:

 function Update () {
     if(Input.GetKeyDown(KeyCode.A)) {
          var mesh : Mesh = GetComponent(MeshFilter).mesh;
          Debug.Log("X:" + mesh.bounds.extents.x + " Y:" + mesh.bounds.extents.y + " Z:" + mesh.bounds.extents.z);
     }
 }  

The other way I can think of is to do the calculation by hand and associate the scale factor in a script. Pick one sphere type to be the base size (i.e. factor 1.0). Figure out how all your other sphere types must be scaled to match the size of the base sphere. Put this value in a public variable in a script that you attach to all the spheres. In a collision, use GetComponent() to get this script and then use the value.

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
avatar image
1

Answer by Owen-Reynolds · May 26, 2013 at 03:35 PM

Seems would have been easier to make them all the same sizes in blender. But, you could use the parenting trick to make them all the same relative size:

 empty parent with script/collider ... scaled 1
    too big size-5 ovaloid, scaled 0.2 so it fits pretty well in a size 1 sphere
    (no one will ever touch the transform of this child)
Comment
Add comment · Show 1 · 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
avatar image robertbu · May 26, 2013 at 04:06 PM 0
Share

@Owen - nice.

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

14 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

Related Questions

Recommended Sphere Texture size? 1 Answer

use iPhoneUtils.PlayMovie. Change size? 0 Answers

Can you scale a Mesh independently of it's Collider? 1 Answer

Difference between sizes 1 Answer

Max scale in unity3d 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