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 Uriel_96 · Aug 20, 2011 at 05:47 PM · colliderpositionscalesize

Set Colliders at same size

I am working on a system of make the player cover in a wall(the system of cover is already done), so I have a wall that inside of that object it has 4 empty objects that are set in the 4 edges of the rectangle wall and these 4 empty objects have a box collider that are trigger and all is fine until I decide to scale the wall bigger or smaller, the 4 empty objects grow too and I want that when you scale it the empty objects change the position but not the scale. I want an easy idea with no use of script but if is not possible, with script is ok.

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
Best Answer

Answer by aldonaletto · Aug 20, 2011 at 07:49 PM

There's no way to keep the original size without scripts when you change the parent scale at runtime. Calculate the original object scale (it's **initial scale parent scale* - the function Vector3.Scale does this multiplication), then anytime the parent scale changes, divide each original scale component (x, y, z) by its corresponding in the new parent scale.

private var orgScale: Vector3; // original child scale before parenting private var lastScale: Vector3; // last parent scale

function Start () { lastScale = transform.parent.localScale; // calculate the original child scale (localScale * parentScale) orgScale = Vector3.Scale(transform.localScale, lastScale); }

function Update () { var dadScale = transform.parent.localScale; if (dadScale != lastScale){ // if daddy changed scale... var newScale = orgScale; // calculate new child scale: newScale.x /= dadScale.x; newScale.y /= dadScale.y; newScale.z /= dadScale.z; transform.localScale = newScale; // set child scale at once lastScale = dadScale; // remember last parent scale } }

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
0

Answer by V-Jankaitis · Jan 12, 2017 at 04:36 PM

 if (Size != Old_Size && SphereColider != null)
         {
             SphereColider.radius *= Old_Size / Size;
         }
 transform.localScale = new Vector3(Size, Size, Size);

Old_Size = Size;

important part is "*= Old_Size / Size;"

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Permanent space between objects 2 Answers

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

Wheelcolliders bug ? 1 Answer

Positioning gameobjects by a corner, not by center 0 Answers

Move position of box collider using javascript 1 Answer


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