I need to create a terrain that moves under a vehicle, but some small meshes that appear on the terraine as it rolls must appear randomly. How could that be done or where should I start looking to find a solution?

  • $\begingroup$ Can you give us an idea of how the 'rolling terrain' works ? That might be relevant. $\endgroup$
    – Robin Betts
    Feb 24 at 19:05

1 Answer 1


You might find this useful. I used a script to step through the objects in a collection named "terrain obstacles" where I want the Visibility::Render to be enabled and disabled on stable random frames (frame numbers set up at random before rendering begins):

enter image description here

I then used a script that, for each object in the collection, add a scripted driver function that is based on the appear and disappear values: enter image description here

The script I include in my file:

### initalize all "terrain obstacles" with a render driver based on random start and end frames

import bpy
import mathutils.noise as noise

for o in bpy.data.collections['terrain obstacles'].all_objects:

    frameAppear = int(noise.random() * (bpy.context.scene.frame_end / 2))
    # be sure that value for 'frame disappear' > 'frame appear'
    frameDisappear = int(frameAppear + (noise.random() * (bpy.context.scene.frame_end / 4)))
    # add a driver to the 'hide_render' property
    print("adding driver to 'hide_render' for object", o.name )
        pass  # ignore possible exception        
    d = o.driver_add('hide_render')
    v = d.driver.variables.new()
    v.name = 'frameNumb'
    t = v.targets[0]
    t.id_type = 'SCENE'
    t.id = bpy.context.scene
    d.driver.type = 'SCRIPTED'
    d.driver.expression = 'False if ((frameNumb > '+str(frameAppear)+') and (frameNumb < '+str(frameDisappear)+')) else True'

If you run the script again, it will change the appear and disappear times of the objects in the collection. You might want to adjust the formula I used to get the appear and disappear numbers. Note that the expression seems backwards (true/false logic): that's because the setting is hide render, not render.


You must log in to answer this question.

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