Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • 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 position it away from the soft body, so move it until you see the object is in the camera's focus.
  • Switch to camera view with the 5 key.
  • 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.

Code Block
languagepy
# Get the soft body (also works with any other object: active rigid body or animated)
# Get the helper null, the (number of) vertices and define a null vector
softBody   = scene.getObject("Rocket01")
null       = scene.getObject("Null01")
vertexList = softBody.getVertices()
numVert    = float(len(vertexList))
pos        = Vector.new(0.0,0.0,0.0)

...



# Go through the soft body's vertices and add up all positions
for vertex in vertexList:
	pos += vertex.getPosition()

...



# Calculate the object's midpoint by averaging positions 
centreOfGravity = Vector.new(pos.getX() / numVert, pos.getY() / numVert, pos.getZ() / numVert)

...


# Apply the centre of gravity to the null object 
null.setParameter("Position", centreOfGravity)