1
$\begingroup$

I want to create a few animations of a flying ball with initial velocity and get its collision point with a wall. Therefore I created a sphere and 2 keyframes (using animated option in rigid body). At the second keyframe I turned off the animated option to let the physic engine take over. Everything works fine until now. For my purposes, however, I need to track the coordinates of the sphere to get the collision point with the wall. During the animated part, I can use

obj.location

For the second part I found out that

ob = bpy.data.objects['Sphere']
bpy.context.scene.frame_current = some_number
bpy.context.scene.update()
print(ob.matrix_world.to_translation())

works. However, as soon as I want to loop over all frames:

for i in range(1,max_frames):
    bpy.context.scene.frame_current = i
    bpy.context.scene.update()
    print(ob.matrix_world.to_translation())

it is not working anymore, e.g. it always prints the starting position. It seems that update() does not update the position correctly, I found the "set_frame" method in some older posts but it seems not to exist anymore in v2.77. Any suggestions how I could solve this problem?

$\endgroup$
1
  • $\begingroup$ I'm just guessing, but have you yet baked the physics simulation? $\endgroup$
    – Mutant Bob
    Commented Jun 10, 2016 at 15:33

1 Answer 1

1
$\begingroup$

Replace

bpy.context.scene.frame_current = i
bpy.context.scene.update()

with

bpy.context.scene.frame_set(i)

scene.frame_current = x might appear to work as expected in the python console, but in scripts like in you q, which demonstrates why not to use it, as its value not used in the scripts execution.

$\endgroup$
2
  • $\begingroup$ Thanks a lot! That was exactly what I was looking for. Although I cannot understand why they removed the method "set_frame" and replaced it by "frame_set". $\endgroup$ Commented Jun 10, 2016 at 17:49
  • $\begingroup$ One reason would be if there was a set_frame it wouldn't appear using autocomplete for scene.frame_ , whereas frame_set() will be listed with other frame properties. Using set_ first would lead to a big, and hence less useful list IMO. $\endgroup$
    – batFINGER
    Commented Jun 11, 2016 at 3:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .