I want to capture freely falling objects from their reference frame. i.e. to have the camera freely falling due to gravity in the exact same manner. Is there a simple way to make a camera free fall just like a Rigid Body?
3 Answers
No python needed.
Simply add a Copy Location constraint to the camera. Set the Target to an object with an active rigid body. (I simply duplicated one of my colorful cubes and moved it back from the rest of the bunch. Remember to turn the visibility off). That will get the camera to fall down with gravity.
To get the nice camera shake when it hits the ground we need two more constraints. A Copy Rotation constraint and a Track To constraint.
The Copy Rotation is copying the rotation of the same cube the camera is glued to, that gets the real shake from the impact with the ground. (I have the Influence of that set to 0.5 just to tone it down a bit.)
The Track To is to keep all my cube in frame. (you can see how much the cubes tumble, and without this constraint the camera would do that too.)
These are my constraints on the camera. Do note the object "Cube.001" is the cube I moved off screen for the camera, and the "Cube" is simply one in the middle of the pack.
You can do this even easier. Just Parent Camera to one of the Cubes faces.
- Select Cubes face.
- Place Cursor on it - Shift+S > Cursor to Selected.
- Select Camera and place it on Cursor position - Shift+S > Selection to Cursor.
- Select Camera first then Cube with Shift and Ctrl+P > Object.
- Done.
Note: Based on the initial Camera position/face selected you will need to set Camera rotation accordingly.
I solved it by adding a cube, letting it fall and baking its keyframes. I then used the cubes baked positions as the camera's. Since this is not exactly what I wanted, I'm leaving the question open. My code is here for anyone to use:
import bpy
cube = bpy.data.objects['Cube.009']
camera = bpy.data.objects['Camera']
sce = bpy.context.scene
for i in range(300):
sce.frame_set(i)
camera.location.z = cube.location.z
camera.keyframe_insert(data_path='location', index = 2, frame = i)