www.xbdev.net
xbdev - software development
Thursday June 26, 2025
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.

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=30location=(000))
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=2location=(spacing0spacing))
        
cube bpy.context.object
        bpy
.ops.rigidbody.object_add()
        
cube.rigid_body.mass 1

# Add projectile cube
bpy.ops.mesh.primitive_cube_add(size=2location=(5, -105))
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, -105)
projectile.keyframe_insert(data_path='location'frame=1)
projectile.location = (505)
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, -3020), rotation=(1.300))
bpy.context.scene.camera bpy.context.object

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





 
Advert (Support Website)

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