2

I saw some documents saying that there is no concepts of length in Unity. All you can do to determine the dimensions of the gameobjects is to use Scale.

Then how could I set the overall relative dimensions between the gameobjects?

For example, the dimension of a 1:1:1 plane is obviously different from a 1:1:1 sphere! Then how could I know what's the relative ratios between the plane and the sphere? 1 unit length of the plane is equal to how much unit of the diameter of the sphere!? Otherwise how could I know if I had set everything in the right proportion?

dbc
  • 104,963
  • 20
  • 228
  • 340
Pikachu620
  • 483
  • 4
  • 17
  • Note we prefer a technical style of writing here. We gently discourage greetings, hope-you-can-helps, thanks, advance thanks, notes of appreciation, regards, kind regards, signatures, please-can-you-helps, chatty material and abbreviated txtspk, pleading, how long you've been stuck, theistic invocations and religious proselytism, voting advice, meta commentary, etc. Just explain your problem, and show what you've tried, what you expected, and what actually happened. – halfer Jun 21 '18 at 08:05
  • But how can I express my gratefulness!?!?!? People take time and effort answer my question, to me it's just a simple courtesy to let them know that I'm truly grateful!!! – Pikachu620 Jun 21 '18 at 09:10
  • I hear you, and the general answers you'll get here is that gratitude (a) can be assumed by default, and (b) can be expressed with upvotes and accept votes as appropriate, and (c) can be expressed by writing a self-answer if the question author feels this would be helpful for a future reader. Old hands are fond of saying **Stack Overflow is not a forum** - if you craft your material to be closer to a piece of technical writing, that is a much clearer and fluff-free way to benefit your thousands of future readers. – halfer Jun 21 '18 at 09:52
  • Useful references [are here](https://meta.stackoverflow.com/q/260776/472495) and [also this](https://meta.stackoverflow.com/q/288160/472495), and there's very likely to be many more on Meta. – halfer Jun 21 '18 at 09:52
  • 1
    Ok... I got it! Than... uh... never mind!!! XP – Pikachu620 Jun 21 '18 at 09:58
  • Heh, thanks Pikachu620! While posting a comment for the purposes of adding thanks or "+1" is gently discouraged (one can merely upvote a post or comment to do the same thing), no-one will mind if you sneak one in while commenting about something else, like I have done here. `:-)` – halfer Jun 21 '18 at 10:03

3 Answers3

1

Well, what you say is right, but consider that objects could have a collider. And, in case of a sphere, you could obtain the radius with SphereCollider.radius.

Also, consider Bounds.extents, that's relative to the objects's bounding box. Again, considering the Sphere, you can obtain the diameter with:

Mesh mesh = GetComponent<MeshFilter>().mesh;
Bounds bounds = mesh.bounds;
float diameter = bounds.extents.x * 2;
Andrea
  • 6,032
  • 2
  • 28
  • 55
1

All GameObjects in unity have a Transform component, which determines its position, rotation and scale. Most 3D Objects also have a MeshFilter component, which contains reference to the Mesh object.

The Mesh contains the actual shape of the object, for example six faces of a cube or, faces of a sphere. Unity provides a handful of built in objects (cube, sphere, cyliner, plane, quad), but this is just a 'starter kit'. Most of those built in objects are 1 unit in size, but this is purely because the vertexes have been placed in those positions (so you need to scale by 2 to get 2units size).

But there is no limit on positinos within a mesh, you can have a tiny tiny object od a whole terrain object, and have them massively different in size despite keeping their scale at 1.

You should try to learn some 3D modelling application to create arbitrary objects.

Alternatively try and install a plugin called ProBuilder which used to be quite expensive and is nowe free (since acquired by Unity) which enabels in-editor modelling.

Scales are best kept at one, but its good to have an option to scale - this way you can re-use the spehre mesh, or the cube mesh, (less waste of memory) by having them at different scales.

zambari
  • 4,797
  • 1
  • 12
  • 22
  • You mentioned the scales are best kept at one! Is it because the bigger the scale is, the more memory and process time it going to take!? – Pikachu620 Jun 15 '18 at 09:53
  • no, scales are always processed anyways, scale is a part of Matrix4x4 that is used for transforming geometry pretty much always, internally, so there is no memory or performance gain (unless unity uses some clever optimalisations), but problems arise when you accidentally apply non-uniform scale to an object that has children which get rotated, this leads to some nasty geometry skews. Uniform scales are all right, its just simpler if everything that doesn't need to be scaled isn't, sometimes it lets you avoid some Transform.transformPoint calls – zambari Jun 15 '18 at 11:39
1

In most unity applications you set the scale to some arbitrary number.

So typically 1 m = 1 unit.

All things that are 1 unit tall are 1 m tall.

If you import a mesh from a modelling program that is the wrong size, scale it to exactly one meter (use a standard 1,1,1 cube as reference). Then, stick it inside an empty game object to “convert” it into your game’s proper scale. So now if you scale the empty object’s y axis to 2, the object is now 2 meters tall.

A better solution is to keep all objects’ highest parent in the hierarchy at 1,1,1 scale. Using the 1,1,1 reference cube, scale your object to a size that looks proper. So for example if I had a model of a person I’d want it to be scaled to be roughly twice as tall as the cube. Then, drag it into an empty object of 1,1,1 scale this way, everything in your scene’s “normal” size is 1,1,1. If you want to double the size of something you’d then make it 2,2,2. In practice this is much more useful than the first option.

Now, if you change its position by 1 unit it is moving effectively by what would look like the proper 1 m also.

This process also lets you change where the “bottom” of an object is. You can change the position of the object inside the empty, making an “offset”. This is Useful for making models stand right on the ground with position y=0.

Adam B
  • 3,662
  • 2
  • 24
  • 33