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 Irsan · May 08, 2011 at 07:38 AM · variablescubefinddimensionsequal

Finding the dimensions of a cube, exploiting them.

This is a bit tricky; I want to find the dimensions of a cube, take those numbers, input them into an equation one-at-a-time, and then end up with three new numbers as the result.

Let's say I have a 4x2x10 cube. I take those dimensions, and put each one through the same equation, to get three new numbers:

"Using "25/(x/2)"

.25/(4/2) = 0.125
.25/(2/2) = 0.25
.25/(10/2) = 0.05

How can I do that?

Comment
Add comment · Show 1
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 Jessy · May 08, 2011 at 09:22 AM 0
Share

Division is slow, so you should consolidate .25/(x/2) into .5/x.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Cyb3rManiak · May 08, 2011 at 08:05 AM

Didn't quite understand it, but the basics will be the same no matter what you want to do with them.

If the cube started off as the basic cube that you can create in Unity - it's dimensions are 1x1x1 units on creation. When you scale it, or parent it and scale the parent - you simply alter the scale factor of its' transform. To get the correct scale you can use Transform.lossyScale. Read up on it, since it's not 100% accurate in some cases where the transform you're checking has a parent that is skewed. This will give you the global scale of the object. If you need a scale compared to it's parent - use Transform.localScale.

When you're starting out, try and start with a simple hierarchy to see how it works. No parent, then one parent and so on. Try and rotate the parent and children to see if your script still works if the objects are not exactly at the same rotation and scale.

Comment
Add comment · Show 2 · 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 Irsan · May 08, 2011 at 08:57 AM 0
Share

Well, lossyScale is read-only. How am I supposed to utilize the numbers themselves?

avatar image Cyb3rManiak · May 08, 2011 at 01:27 PM 0
Share

That really depends on how you WANT to utilize them, isn't it? :) If you mean you want to shrink or grow the same box you're measuring- make sure it's not parented to anything (to avoid miscalculations of the original scale), or that the scale of all objects is not skewed and just use transform.localScale. Use the method Jessy posted, and just plug the resulting Vector3 into transform.localScale: transform.localScale = ThreeNewNumbers(transform.localScale);

avatar image
0

Answer by Jessy · May 08, 2011 at 08:45 AM

Vector3 ThreeNewNumbers (Vector3 dimensions) {
    for (int i = 0; i < 3; ++i) dimensions[i] = .5F / dimensions[i];
    return dimensions;
}
Comment
Add comment · Show 3 · 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 Irsan · May 08, 2011 at 10:54 PM 0
Share

It gives me "Assets/NewBehaviourScript.js(1,8): UCE0001: ';' expected. Insert a semicolon at the end." on the first line, even though I already have one.

avatar image Jessy · May 08, 2011 at 11:55 PM 2
Share

I didn't give you JS code.

avatar image Gotal Jessy · Sep 20, 2017 at 09:19 PM 0
Share

hahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahahaha

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

1 Person is following this question.

avatar image

Related Questions

Why are objects with same x,y,z dimensions invisible? 0 Answers

Find gameObject with higher variable 1 Answer

Finding cube corners 4 Answers

Is there a way to edit the dimensions of a gameobject such as a cube or a plane? 2 Answers

Getting size-dimensions from the other collider. 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