2
$\begingroup$

I try to simulate dynamic behavior in blender using physics for rigid bodies. Some objects should fall down onto a moving plane.

(there is a previous question related to that: animation locations with python but the positions seems just to scratch the surface of the problem).

I would like to animate the plane depending on the falling objects positions, so that they interact with the falling objects (e.g. do rotations of the plane). But I would like to set coordinates dynamically while running the simulation (running the animation here means: counting scene.current_frame manually).

One aspect of the simulation works fine: if I increment the current_frame, the objects with rigid_body = active do fall down. But changes in rotations of the plane seem to be not recognized. A bpy.ops.transform.rotate(value=2,orient_axis = "X") seems not to be recognized during the animation.

Is there a way to consistently implement dynamical changes of the environment while stepping through the frames (without adding keyframes for the dynmaically changing rotation and position of the plane, ) so that they dynamically interact with the rigid_bodies?

The planes physics property is set to passive rigid_body.

To demonstrate the issue, here is the blend-file:

Please run the script, which starts a frame_handler. Then start the animation (from frame 1 to 100). In frame 10 the cup is turned upside down from the script. this is visible in the viewport, but the sphere still seems to falls into the original (unrotated) cup. So the physics calculation does not seem to recognize the rotation, althought the viewport does.

So how can I inform/adapt the environment, on which the physics calculations rely about/to the changes in the cup rotation?

-> edit: one additional thought after experimenting with the physics parameters: if I also set the cup as an active rigid boy (and place it onto an additional plane, which is passive then), the rotation will be integrated into the physics simulation.

but this unfortunatley has the side effect, that the dynamics of the system is compelelty differnt. To fix this, might be more complicated than to understand the structural way blender python interacts with the physics environment.

  1. edit: I found some interesting information here: https://www.youtube.com/watch?v=YpUyGJ-do4o

So following the ideas in the video one approximation to the combination between external control and integration into physics calculation could be to set the rigid body settings to "animated" in e.g. each odd frame, and then to "dynamic" in each even frame. This allows a possibilty to set positions and rotations via a python script and let the changed values be incorporated into the physics calculations.

Anyway: even better would be a bpy way to set positions directly into the physics world in arbitrary frames, to get a fluid frame by frame simulation with external control of some objects.

$\endgroup$

2 Answers 2

1
$\begingroup$

I tried this:

      frm = scn.frame_current
      if (frm % 2) == 0:
          cup.rigid_body.kinematic = False
      else:
          cup.rigid_body.kinematic = True                  
      cup.rotation_euler.rotate_axis('X',math.radians(rotVal  ))

and it surprisingly works.

Here is the blend file:

Of course this is only an approximation. Even better would be to directly change the data, which are actually taking for the physics calculations to have more control about the simulation.

$\endgroup$
0
$\begingroup$

Meanwhile I found out, that usage of drivers (using an empty as driver to control the rotation) also solves the problem, so that circumstancial resetting the kinematic-variable is not necessary with this driver-approach.

$\endgroup$

You must log in to answer this question.

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