# Two moving bodies collision

What is the right way to create two moving bodies collision by script? Since both of the objects been animated they collapse into each other when colliding. How can I prevent this from happening?

Part of my code:

bpy.data.objects['Cube'].rigid_body.kinematic = True
bpy.data.objects['Cube'].location = [-5,-5,1]
bpy.data.objects['Cube'].keyframe_insert(data_path='location', frame=1)
bpy.data.objects['Cube'].location = [0,0,1]
bpy.data.objects['Cube'].keyframe_insert(data_path='location', frame=20)
bpy.data.objects['Cube'].rigid_body.kinematic = False

bpy.data.objects['Sphere'].rigid_body.kinematic = True
bpy.data.objects['Sphere'].location = [5,-5,1]
bpy.data.objects['Sphere'].keyframe_insert(data_path='location', frame=1)
bpy.data.objects['Sphere'].location = [0,0,1]
bpy.data.objects['Sphere'].keyframe_insert(data_path='location', frame=20)
bpy.data.objects['Sphere'].rigid_body.kinematic = False


In this setup, you will need to add keyframes for the kinematic property. The kinematic property should be enabled during the beginning so that the object movement is controlled by the animation. Right before the two objects collide, the kinematic property should be disabled so that the rigid body simulator takes control over the object movement.

Here is an example for how to modify your script so that the kinematic property is disabled at frame 12:

bpy.data.objects['Cube'].rigid_body.kinematic = True
bpy.data.objects['Cube'].keyframe_insert(data_path='rigid_body.kinematic', frame=1)
bpy.data.objects['Cube'].location = [-5,-5,1]
bpy.data.objects['Cube'].keyframe_insert(data_path='location', frame=1)
bpy.data.objects['Cube'].location = [0,0,1]
bpy.data.objects['Cube'].keyframe_insert(data_path='location', frame=20)
bpy.data.objects['Cube'].rigid_body.kinematic = False
bpy.data.objects['Cube'].keyframe_insert(data_path='rigid_body.kinematic', frame=12)

bpy.data.objects['Sphere'].rigid_body.kinematic = True
bpy.data.objects['Sphere'].keyframe_insert(data_path='rigid_body.kinematic', frame=1)
bpy.data.objects['Sphere'].location = [5,-5,1]
bpy.data.objects['Sphere'].keyframe_insert(data_path='location', frame=1)
bpy.data.objects['Sphere'].location = [0,0,1]
bpy.data.objects['Sphere'].keyframe_insert(data_path='location', frame=20)
bpy.data.objects['Sphere'].rigid_body.kinematic = False
bpy.data.objects['Sphere'].keyframe_insert(data_path='rigid_body.kinematic', frame=12)
$$$$
`
• It works but this way isn't convenient since my plane has a friction parameter which may result that the cube (which has a more shared surface with the plane) won't get to its target location because of that. The Ideal thing would have been to change the kinematic properties one frame before the collision, but since I'm using scripting without GUI it's much harder to do that. Is there a more convenient way to do what I'm trying? – AvivSham Sep 28 '19 at 10:09