- Home /
How to calculate distance in meters?
Hi, i have a code to calculate the distance from one object to another, but not sure if this is in meters or what, how can i make this in meters to get an accurate calculation with all my objects?
Thanks!
....this is the code:
var other : Transform;
if (other) {
var dist = Vector3.Distance(other.position, transform.position);
print ("Distance to other: " + dist);
}
...and if the distance its messured from the origin of the object to the origin of the other object, how about to calculate from the collide side to the collide side of the other object for example?, just guessing...perhaps the better way its using raycast?....
Answer by eatsleepindie · Sep 05, 2014 at 05:41 AM
The units in Unity can represent whatever you want. As long as you keep the units consistent throughout, which in your case would be 1 game unit = 1 meter, then you can use any standard of measurement you want. So, a standard Unity cube would be 1 meter x 1 meter x 1 meter, which you can use to eye measurements. So, scaling a humanoid to be about 2 cubes high would make them 2 meters high, or a bit over 6 feet.
Great, thanks, so for games with a human scale its good to make this meter to meter calculation (makeing a model in meters to use it in Unity), and use meters as Unity units, and the distance showed by the code will be meters then.
You can use a 1 foot equals 1 game unit system if you prefer. $$anonymous$$eters is pretty standard for the industry, but as long as you kept everything consistent, you can definitely use a 1 Ft: 1 GU setup. If you were building a city game you might use 1 mile : 1 game unit, etc. If you were building a game featuring insects, it may be more sensible to use a 1 inch : 1 GU setup.
$$anonymous$$eep in $$anonymous$$d that the Physics in Unity assumes 1 unit = 1 meter.
@eatsleepindie - I'd disagree that metres is a standard for the industry. $$anonymous$$ax defaults to inches and $$anonymous$$aya uses centimetres, for example (http://blogs.unity3d.com/2011/09/02/art-assets-best-practice-guide/). The most important thing is consistency, not just within the scale of your models, but in any physics calculations etc.