I’m new to working with unity and I’m working on a simple game. One issue I’ve been running into is scale and I am curious if anyone can offer some suggestions or clear some of this up for me.
The problem I am encountering is that I don’t see anyway to work in real units such as meters or feet. When I import a model from maya it seems to maintain it’s original scaling. Under scale for x,y,z in the inspector it says 3 - whatever that is. If I create a cube and set it’s scale to 3 it’s much smaller than the model So I assume the scale is just refering to the percentage of the original models size rather than an actual unit of measurment. So is there a way to do this, to reference actual dimensions?
In 3d graphics there is no absolute scale. There’s just units. If something is length 3 all that means is that it’s 3x longer than something of length 1.
3d packages which choose to use real world units are simply creating an illusion. Much like if you draft a plan and write “scale: 1 mm = 100 m” on it. This is only so if you believe it, and only accurate if you’re not looking at an enlarged or reduced copy.
The only place that real world scale actually exists in unity is in physics, where the default gravity constant is 9.8 meters per second per second acceleration. If that is true, then the built in cube is one meter on each side and each world unit is one meter. It is recommended that you use real world scale in your games at least at first because it simplifies things.
… oh wait. I just realized that both tonio and I misunderstood what you are asking. It sounds like you want to scale your models’ bounds sizes directly, instead of using the default relative scale. The inspector uses relative scale because it makes most sense, but you can set absolute size in a script.
// I am assuming that I have no rotation or parent
var newSize = Vector3;
function Start ()
{
var size = renderer.material.bounds.size;
var scale = Vector3(newSize.x / size.x, newSize.y / size.y, newSize.z / size.z);
transform.localScale = scale;
}
thanks for the code. Helpful… well… I have done as you’ve described… but I’m not finding the output. Does this display in the inspector, or in the output when the project is compiled?
So this is wierd. In maya I specifically have my game object (skeeball machine) scaled to about 5.7 meters. Importing the same model in unity and it becomes about 570 units. Obviously I could scale down the model to 1/10th the size, but I must be doing somthing wrong here… Any ideas? (See attached .gifs)
Thanks for bearing with me. I had been selecting only the object instance, not the object in the project folder. So here are the import settings. Doesn’t look like its set to scale anything.
I’d change “mesh scale factor” to 0.1, and then decide what you want to do with the other settings. I usually turn off “automatically calculate normals” and set “one material for every material in the scene”.
I cobbled together a quick and dirty custom inspector based shamelessly on the code for the menu item listed above. I prefer the information to be displayed this way. It pops up with the other inspectors every time you select a GameObject.
Thanks to forestjohnson like 3 years ago for the original code, which has been a huge help to me. 8)
// put me in /Assets/Editors/PrintSelectionSize.js
@CustomEditor(GameObject)
class PrintSelectionSize extends Editor {
function OnInspectorGUI() {
var first = true;
var bounds : Bounds;
var renderers = Selection.GetFiltered(Renderer, SelectionMode.Deep);
for (var r : Renderer in renderers) {
if (first) {
bounds = r.bounds;
} else {
bounds.Encapsulate(r.bounds);
}
first = false;
}
EditorGUILayout.BeginHorizontal();
EditorGUILayout.LabelField("World Dimensions", bounds.size.ToString());
EditorGUILayout.EndHorizontal();
}
}