Python scripts for controlling camera and object motion

Hello there,

I’m new to Blender and its Python interfact. What I want to do is to generate a short 3D animation with a car rigidly moving on the ground plane watched by a also moving camera.

I’m learning how to do this manually in Blender. However, with a sequence of hundreds of frames and the need of precise control of the camera and object motion, I would really need to do this in Python scripts. Are there any Python scripts that are related to this?

Several specific questions:

  1. How to control the camera motion? Assigning a IPO curve to it in the way similar with the object?
  2. How to make the camera tracking the moving car? I mean doing this using Python scripts?

Really appreciate your help. Thanks a lot.

Do you really need python here or can you do this by simply parenting the camera to the car?

Another way that gives more interesting camera movement is to use keyframes and a Track-To constraint on the camera.

Thanks for your reply.

The reason why I need Python script is that I want to control both the object and the camera precisely. I can compute their pose and positions for every frame. For a hundred-frame sequence, manually assigning the IPO curve would be rather tedious.

By camera motion, I mean the camera is not only tracking the object but itself is also translating. I guess if I set up the track-to constraint or parent the camera to the car, the camera will only rotate but not translate. Please correct me if I’m wrong.


Trackto --> rotate only and the object can not have rot ikey
Parent --> translate only … but can rotate around the parent if the parent rotates on itself . The child can have its own rot/scale/tranlate ikeys

First make sure you understand keyframe animation. A hundred frames is only 3~4 seconds and rather complex things can be done by simply setting a couple keys and adjusting the interpolation handles. A hundred frames does not need a hundred keys.

Then, go look at the docs for the Object module. This is where you get and set the location and rotation of objects. The camera is simply another type of object.

On-Frame-Change scriptlinks are useful for this sort of thing.

Example :