A coordinate is a point in space. Moving or not doesn’t matter because the distance between points remains constant.
If you scale the model however, it will change.
And if you rotate the model, the lowest point in z may also change.
But you don’t know where this point is, so that’s the more immediate problem. Getting the median of a quad requires a little bit more fiddling so that’d be your homework; look into mesh polygons for that.
Here is an approximation going by lowest points, only because it is more convenient and easier for me to explain.
from bge.logic import getCurrentController;
from mathutils import Vector;
own=getCurrentController().owner; me=own.meshes[0];
low_point=Vector([0,0,0]); points=[];
for matid in range(me.numMaterials):
for vi in range(me.getVertexArrayLength(matid)):
vert=me.getVertex(matid, vi); co=vert.XYZ;
co=(Vector([co.x, co.y, co.z, 1])*own.worldTransform).xyz;
if co.z < low_point.z:
low_point=co;
if co not in points: points.append(co);
points=[co for co in points if co.z==low_point.z];
low_point=Vector([0,0,0]);
for co in points:
low_point+=co;
low_point=low_point/len(points);
low_point.xy = -low_point.xy;
dist=low_point.length;
What goes on in here is I iterate through each vertex in the mesh, move them around according to object transforms, compare the z values and get the lowest. Finally, I take the median XY point between all points whose Z is equal to the lowest point, giving you something close to the center point of the lowest edge.
Finally, since all vertex positions are relative to the origin, the length of the resulting vector should be equal or at least fairly close to the distance you want.
For testing, I made a red icosphere snap to the final position of low_point
and made a cuboid rotate along X and Y. Here’s what that looks like:
Do note that this isn’t very performant for real time, and worse still on complex meshes. Your best bet might be caching the results for later use rather than calculating them on the spot.