Add the script to Simulation Flow (Ctrl/Cmd + F2) > FramesPost.
By default it is not possible to parent a camera or other objects to a soft body, because soft bodies do not expose any position data during a simulation. You can see this when you monitor a soft body's "Position" values: all XYZ values remain constant and only the initial position is displayed.
Scene Preparation
- Create a ground object and set its "Dynamics" option to "Passive rigid body".
- Add a rocket object ("Rocket01") and set its "Dynamics" option to "Soft body".
- Add a null ("Null01") and a "Gravity" daemon.
- Create a camera and move it until you see the object in the camera's focus.
- SceneCamera01 > Node Params > Node > Parent to > Null01
- SceneCamera01 > Node Params > Camera > Link target > Null01
The script takes the soft body's vertex positions and uses them to calculate the rocket's centre of gravity. This position vector is then transferred to the null object.
softBody = scene.getObject("Rocket01") null = scene.getObject("Null01") vertexList = softBody.getVertices() numVert = float(len(vertexList)) pos = Vector.new(0.0,0.0,0.0) for vertex in vertexList: pos += vertex.getPosition() centreOfGravity = Vector.new(pos.getX() / numVert, pos.getY() / numVert, pos.getZ() / numVert) null.setParameter("Position", centreOfGravity)