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 the object is 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.

Code Block
languagepy
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)