Getting the location of rigid body object at current keyframe I would like to print out the location of an object with this script:

import bpy

obj = bpy.data.objects["Cube"]
print(obj.location)


It prints it out correctly, but when I animate this object (it's a rigid body) and then at a particular keyframe I run this script again, it just prints out the same location.

I tried to set the frame with:

bpy.context.scene.frame_set(fr)


Like it is mentioned in these two questions:


How can I get the location of an object at each keyframe?
Location of an object at a specific frame


But the location just stays the same. How can I get the correct location of the cube?
Use:

import bpy

obj = bpy.data.objects["Cube"]
print(obj.matrix_world.translation)


This gives you the location from object's matrix which changes each frame for rigid bodies