Login

Fancade Wiki

some rewriting, with help from 585hubert

... ...
@@ -1,11 +1,15 @@
1
Normally, when you get the position of an object, you actually get the position of the object's *center of mass*. In most cases this is enough, but when the object's center of mass *isn't the same as its geometric position*, and you want to locate it (or locate something in it) geometricly, just "getting its position" won't cut it.
1
When you get the position of an object, you actually get the position of the object's *centre of mass*.
2 2
3 3
[[/uploads/center of mass opaque.png]]
4 4
5
The trick is to take the vector returned by [[Get Position]] and **offset it by half the total size of the object** ("the offset"), with "total size" referring to the minimum and maximum vectors of the object, added together.
5
In most cases, this is enough, as the centre of mass of an object usually corresponds to its geometric centre (or centroid). However, in cases where they do not align, and you wish to get the geometric centre, getting its position will thus not suffice.
6
7
The centre of mass of an object is **not** the same as it's geometric position. The *geometric position* of an object is the midpoint of the vector between it's minimum and maximum vectors, and is the actual center of an object, which doesn't always correspond to the centre of mass of the object.
8
9
The trick is to take the [[Get Position]] vector and **offset it by half the total size of the object**. The "total size" of the object refers to the sum of the minimum and maximum vectors of the object.
6 10
7 11
[[/uploads/geometrical position opaque.png]]
8 12
9
By extension, to set the geometric position of the object, set the actual position of the object to the desired position subtracted by the offset.
13
By extension, to *set* the geometric position of the object, set the position (centre of mass) of the object to the desired position (centroid) subtracted by the offset.
10 14
11 15
[[/uploads/set geometrical position opaque.png]]
... ...
\ No newline at end of file
Fancade Wiki