www.xbdev.net
xbdev - software development
Thursday April 30, 2026
Home | Contact | Support | Blender (.py) Scripts... Automating Blender ..
     
 

Blender (.py) Scripts...

Automating Blender ..

 

Rigid Body Wall (Fire Brick)


Let's build a wall of rigid body bricks and fire a cube at it - so it smashes and breaks appart when they collide.

<?php
import bpy

# Clear the scene
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete()

# Create ground plane
bpy.ops.mesh.primitive_plane_add(size=30, location=(0, 0, 0))
ground = bpy.context.object
bpy.ops.rigidbody.object_add()
ground.rigid_body.type = 'PASSIVE'

# Build a wall of cubes (5x5)
wall_width = 5
wall_height = 5
spacing = 2
for x in range(wall_width):
    for z in range(wall_height):
        bpy.ops.mesh.primitive_cube_add(size=2, location=(x * spacing, 0, 1 + z * spacing))
        cube = bpy.context.object
        bpy.ops.rigidbody.object_add()
        cube.rigid_body.mass = 1

# Add projectile cube
bpy.ops.mesh.primitive_cube_add(size=2, location=(5, -10, 5))
projectile = bpy.context.object
bpy.ops.rigidbody.object_add()
projectile.rigid_body.mass = 20
# Optional: Set other properties if needed
projectile.rigid_body.friction = 0.5
projectile.rigid_body.restitution = 0.2  # Bounciness

# Disable rigid body temporarily to set keyframes
projectile.rigid_body.enabled = False

projectile.location = (5, -10, 5)
projectile.keyframe_insert(data_path='location', frame=1)
projectile.location = (5, 0, 5)
projectile.keyframe_insert(data_path='location', frame=20)
bpy.context.scene.frame_set(1)


# Re-enable rigid body and set to animated so physics takes over after keyframes
projectile.rigid_body.enabled = True
projectile.rigid_body.kinematic = True


# Add a camera
bpy.ops.object.camera_add(location=(10, -30, 20), rotation=(1.3, 0, 0))
bpy.context.scene.camera = bpy.context.object

# Add a light
bpy.ops.object.light_add(type='SUN', location=(0, 0, 30))





 
Advert (Support Website)

 
 Visitor:
Copyright (c) 2002-2026 xbdev.net - All rights reserved.
Designated articles, tutorials and software are the property of their respective owners.