Set the origin of an object to the location of an empty.
Together with
Cube.reinstancePhysicsMesh(evaluated=True)
to update the physics mesh we can shift the center of mass in game.
UPBGE_0.3_set_Origin.blend (831.6 KB)
Special thanks to JuanG3D from Discord Channel for providing the bpy-code.
import bpy
import bge
from mathutils import Vector, Matrix
Cube = bge.logic.getCurrentScene().objects['Cube']
Empty = bge.logic.getCurrentScene().objects['Empty']
emptyPosition = Empty.worldPosition
ob = Cube.blenderObject
mw = ob.matrix_world
o = mw.inverted() @ Vector(emptyPosition)
ob.data.transform(Matrix.Translation(-o))
mw.translation = emptyPosition # doesn't have effect in runtime, use:
Cube.worldPosition = emptyPosition
Cube.reinstancePhysicsMesh(evaluated=True)