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 SunilUL · Apr 16, 2018 at 08:02 AM · collidertransformscaleboundsroom

how to scale object to fit inside a room

Problem: I have a room with 4 walls and 1 Ceiling and a floor. Now, there is a Cube to calculate the carpet area. alt text



The cube should hit the wall colliders alt text

so that I can always display dimensions of each wall always in the center by calculating the centre of the carpetArea size calculator

Can someone please help me write this code?

ques-carpetarea.png (20.7 kB)
ques-carpetarea1.png (18.8 kB)
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Harinezumi · Apr 16, 2018 at 08:16 AM

Assuming that the images show a view from above, so that x axis points to the right, and z axis points up (also assuming that the walls are not rotated, but scaled), you calculate the center coordinates of the room using the coordinates and thickness of the wall objects, you average the coordinates to get the center of the carpet cube, and scale it by the difference of the positions:

 float roomMinX = wallD.transform.position.x + wallD.transform.localScale.x * 0.5f;
 float roomMaxX = wallB.transform.position.x - wallB.transform.localScale.x * 0.5f;
 float roomMinZ = wallC.transform.position.z + wallC.transform.localScale.z * 0.5f;
 float roomMaxZ = wallA.transform.position.z - wallA.transform.localScale.z * 0.5f;
 
 GameObject carpetCube = ...; // get the cube from somewhere
 carpetCube.transform.position = new Vector3 ((roomMinX + roomMaxX) * 0.5f, 0 /* or floor height of the room */, (roomMinZ + roomMaxZ) * 0.5f);
 carpetCube.transform.localScale = new Vector3 (roomMaxX - roomMinX, carpetThickness, roomMaxZ - roomMinZ);

This should get you started along the right path, figuring out the rest of the details along the path.

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 SunilUL · Apr 16, 2018 at 10:07 AM 0
Share

This works like a charm. too Amazing...

thanks a lot :D

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

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

Related Questions

Is using a rigidbody/collider based movement script with an XR Rig that has a non-relative XR camera possible? 2 Answers

Ignore Collision Temporarily 1 Answer

Simple Maths Problem - Help! 1 Answer

scalefactor issue 0 Answers

Collider bounds size is 0 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