3
$\begingroup$

Question: How do I get a camera to follow/move with a single particle?

My example: I have created a large particle system and I would like to have the camera sit behind and follow a single particle as it floats around. If i could also have the camera be animatible (moving back and forth left and right as a secondary key framed animation that would be great).

research: this question seems to have been asked before on here, but not answered. Also i found this https://blenderartists.org/t/particle-as-object-for-camera-track-to-constraint/640226 seems like a good idea but i don't know scripting and was not able to get it to work.

$\endgroup$

2 Answers 2

2
$\begingroup$

This script assigns first particle location to another object(In this case Empty). you can parent camera to this object for further manipulation.

import bpy 

ob = bpy.context.scene.objects["Cube"]
target = bpy.context.scene.objects["Empty"]

def my_handler(scene, depsgraph):
    eval_ob = ob.evaluated_get(depsgraph)
    particle_system = eval_ob.particle_systems[0]
    target.location = particle_system.particles[0].location 
         
bpy.app.handlers.frame_change_post.clear()
bpy.app.handlers.frame_change_post.append(my_handler)

If you are looking for alternate solution, i recommend Animation Nodes addon, which can do this more efficiently. enter image description here

$\endgroup$
3
  • $\begingroup$ thank you, the script works. but the empty position does not seem to update during render time. it only updates it position properly when i click select a frame in the time line.(scrubbing with the arrow keys also seems to freeze its position) is there a way to fix this? $\endgroup$ Commented Aug 7, 2020 at 9:07
  • $\begingroup$ @FrotoLaggins I updated the script. Check this works in render $\endgroup$ Commented Aug 7, 2020 at 10:41
  • 1
    $\begingroup$ Of opinion that ob = scene.objects.get("Cube") should be in the handler. The handler will run for its event on any scene. Running code above when one scene has context defines ob. A new blank scene without ob linked will evaluate the object against the depsgraph of another scene, not entirely sure but may or may not be unwanted consequences. $\endgroup$
    – batFINGER
    Commented Aug 7, 2020 at 15:31
1
$\begingroup$

Bake an animation.

Instead of having this "live" via drivers, a handler, etc, etc, can bake the animation of another object to match the path of chosen particle.

Could say this is somewhat similar to the particle systems baked cache in that If the particle system is changed, will need to run script again.

Get particle location using python

Using above, a script to add an empty animated to follow the path of particle 0 of context objects active particle system, across the particle systems frame range.

enter image description here Result on default PS. Falling in Z, notice retains last value after lifetime.

import bpy

context = bpy.context

dg = context.evaluated_depsgraph_get()
scene = context.scene
ob = context.object.evaluated_get(dg)
ps = ob.particle_systems.active
p = ps.particles[0]
locs = []
bpy.ops.object.empty_add()
mt = context.object
f = ps.settings.frame_start
frame_step = 1 
while f <= ps.settings.frame_end:
    scene.frame_set(f)
    mt.location = p.location
    mt.keyframe_insert("location", frame=f)
    f += frame_step

Instead of adding an empty could, look for an object in scene of known name, eg "Target" , clear its animation.

Replace

bpy.ops.object.empty_add()
mt = context.object

With

mt = scene.objects.get("Target")
mt.animation_data_clear()
$\endgroup$

You must log in to answer this question.

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