Simulations Overview

In the Animation chapter, you learned how to add motion to your scenes using the techniques of keyframing and motion paths, using so-called traditional animation tools. Although these techniques can produce impressive results, they still require the animator to define every object movement or attribute change over time. For some types of motion, this can be quite painstaking, and still may not produce results that look realistic. For example, imagine trying to keyframe the motion of a baseball after it has been hit by a batter, or the flight of a golf ball. Even more ordinary, what about a scene where two children throw balls in the air—one is a beach ball and the other a soccer ball. Do you think you could accurately or realistically keyframe the motions of these two balls? Maybe you could, but Realsoft 3D offers tools to make these types of animation much simpler: namely, the Simulation tools.

The simulation tools introduce a completely different approach for producing motion. Instead of defining the changes in an object's position over time, you can actually define a "physical" system (simulated of course) that can be used to control an object's motions. Think of some of the physical properties that exist in the real world: there is gravity, there are electromagnetic fields, there is friction, there are forces exerted on objects by wind and water, and there are properties of objects such as their mass, elasticity, rigidity, surface friction, etc.

When you use simulation, Realsoft 3D computes all motions automatically, and realistically, based on the laws of physics that produce those motions. Through a combination of setting the Physical and Simulation attributes for objects (Phys and Sim tabs of the Property window), you create the type of world in which objects exist; for instance, an Earth-like or Moon-like environment. One advantage is that by using simulation, you can affect (animate) a large number of objects just as easily as a single object.

Our first simulation project is to create an object that emits spheres, which a fan then blows toward a wall. When the spheres hit the wall, they collide and rebound back.

Level: Intermediate

Example project: 'tutorprojects/simulation/firstsimulation'

Start a new project. Select the 'root' object and click the 'Simulation' button shown in the tool control bar. This activates simulation for all objects placed under the root level.

Add a creator object to the scene by selecting 'New/Creator' from the Select window's popup menu. Now create an analytic sphere—place it anywhere you like in the view—and drop it inside the creator object. Your hierarchy should look as follows.

Simulation activated for the root level

Open the Animation window and click the play button. The creator object emits spheres which move in the same direction. This happens, because of the default attribute settings for initial velocity and object lifetime of the creator object.

Creator object including one analytic sphere

Click the 'Simulation' tab on the toolbar, and activate the Fan tool. The Fan tool requires that you enter three points in the view window. The first point sets the anchor position of the fan, the second point sets the length of the fan object, and the third point the width. The width does not matter in this example. Enter the points as shown in the following picture to define the fan object.

A fan created

The object hierarchy should now appear as follows:

By default, all simulation effects are switched off; therefore, the fan will not yet affect the spheres. To turn the fan on so it affects the spheres, select the sphere object and open the Property window. Go to the 'Sim' (simulation) tab and set the 'Fluid Dynamics' property to 'Affected'. Now all spheres emitted by the creator object are duplicates of this sample sphere. All duplicates have the same fluid dynamics properties enabled, and will be affected by the airflow from the fan.

[Note] Note
The fan object should affect the spheres via fluid dynamics. We don't want the spheres to generate any fluid flows. Therefore, we set the 'Fluid Dynamics' field to 'Affected'.

Now play the animation. If you have followed the instructions exactly to this point, you most likely are not seeing any effect on the spheres; that is, they continue in a straight line as if the fan was not working. This is due to the default values for the mass of the sphere (1.0 kilogram) and the wind velocity (10 meters/second) produced by the fan.

Fluid Dynamics enabled for the sphere used by the Creator object

Select the sphere, and on the 'Phys' tab, set its 'Mass' attribute to 0.1.

The default airflow of the fan may also require some adjusting. Select the fan, and on the 'Phys' tab set the 'Fluid Velocity' attribute to 100.0. Now play the animation again. This time, the fan blows the created spheres downward.

The 'Mass' property set to 0.1 for the sphere.

Note that when the animation reaches the last frame, it is automatically rewound to the first frame. If you cancel the animation before it reaches the last frame, you must manually rewind the animation back to the first frame (use the Rewind button).

The final part of this scene is to create a wall into which the spheres collide. We want the collisions to be detected so that the spheres bounce back after hitting the wall.

Create an analytic cube object, and position it so that it is in the way of the spheres blown by the fan. Play the animation and note where the spheres disappear, and place the wall inside of this position. Check from the other orthogonal views to verify that the spheres will hit the cube. If not, adjust the size of the cube.

To make the spheres collide with the wall, you must activate the collision detection effect for both the sphere and the wall. First, multi-select the sphere and the cube, then go to the Property window's Sim tab and set the Collision Detection attribute to 'Both'. (Multi-selecting objects allows you to set one or more attributes to the same value for all selected objects.)

Play the animation and note what happens - the wall is being knocked backward by the collisions with the spheres. There are two reasons for this: first, the mass of the wall is not great enough compared to the mass of the spheres, and second, the wall was set to a Collision Detection value of 'Both', meaning that it is both a cause of collisions, and it is affected by collisions.

Collision detection enabled for the sphere and the cube

To change the behavior of the wall so that it is not displaced by the collisions, first try setting the wall's Collision Detection attribute to 'Cause'. Play the animation. The wall is no longer moved by the spheres. However, it is still a lightweight object, which cannot bounce the objects that much. This combination makes the wall act strangely in the simulation: the locked position does not match its low mass. Reset wall's collision property back to both, and on the 'Phys' tab, set the mass of the wall to 1000.0. When you play the animation again, you'll note that the wall still moves, but is affected far less by the sphere collisions. This is because we still have a frictionless environment; for all practical purposes, the scene we have set up is being treated, physically, as if it were in outer space. To simulate a truly heavy (ground-anchored) wall, change the mass to for example 1000000 kilograms and set the Collision Detection attribute to Cause. Then the wall will not move and has collision behavior of a massive object.

The Collision Detection attribute is set to 'Both' for the sphere. This causes the spheres to collide with both the wall and each other. Change the value for the sphere to 'Affected' and play the animation to note the difference in behavior.

Since you now have a working simulation environment, try testing different values for both the Physical and Simulation attributes of the various objects.

In addition to the attributes available on the 'Phys' and 'Sim' tabs, each object type has type-specific attributes, which are located on the 'Spec' tab. For example, the Fan object has a 'Turbulence' attribute for making the airflow turbulent. This is purely a Fan-specific attribute, which is why it is found on the Spec tab.

Simulations and the object hierarchy

The simulation system has an important relationship with the object hierarchy. The 'Simulation' property, which was turned on in the previous example, is not a global setting that makes all objects in the scene collide and bounce around. Rather, the Simulation property affects hierarchy levels: that is, level objects. The Simulation property controls only the direct sub-objects of the level, and is not propagated into the sub-hierarchies of the level. This situation is shown in the following diagram.

Setting up the Realsoft 3D simulation system to work this way results in an extremely flexible system with very fine-grained control. To demonstrate this, consider a scene where a hammer strikes a ball.

Start a new project, and create two analytic cylinders to form a simple hammer, and an analytic sphere for the ball. Set up the scene as shown in the following illustration. Make sure that the hammer head lines up with the sphere in all directions.

'Simulation' is a level attribute. Simulation will not affect the objects inside the sub-object called 'rigid level'.

Multi-select all three objects, and then choose 'Animations/Simulations/Collision Detection' from the menu bar. Collision detection is now activated for all three objects. Note that choosing this function also sets the Simulation property on in the parent level of the objects, which in this case is 'root'. To verify what the settings are for the three objects, open the Property window to the 'Sim' tab, and check the value of the Collision Detection property for each objec - note that it is set to 'Both' for each object.

A hammer ready to hit the ball

Now select the two parts of the hammer, click the Simulation tab on the toolbar to open it, and activate the Velocity tool. Draw a vertical line in the view window by placing the first point to the right of the hammer's head approximately at its center, and the second point about one major grid unit below the sphere. This line represents how much the hammer moves in one second.

Now play the animation. When the hammer strikes the ball, the hammer breaks. This happens because the parts of the hammer are treated as individual objects in the simulation, and no force is holding the parts together. To change the behavior, you need to change the object hierarchy.

First, stop animation playback and rewind it to the first frame. In the select window, right click and choose 'New/Level' from the popup. Rename this new level as 'hammer'.

Select both cylinders and drag & drop them into the "hammer" level. The hierarchy should now look as follows.

A new hierarchy for the simulation

Play the animation. This time nothing happens! This is because the cylinders are now enclosed in a new hierarchy level that has no simulation attributes set yet. We will have to redefine the physical properties for the new level object called 'hammer'.

Select the 'hammer' level and then choose 'Animation/Simulations/Collision Detection' from the main menu. Open the 'Simulation' tab on the toolbar, and activate the Velocity tool. Draw a velocity line like you did previously.

Play the animation. Now the parts of the hammer remain firmly attached, and the ball moves away after being struck. However, note that the hammer is still affected by hitting the ball - it spins as if no one were holding it. Of course, no one is holding the hammer, but what if you wanted it to behave that way? A good question, but that is a topic for later. If you like, experiment with the value of the Collision Detection attribute of the objects, or the mass values of the objects and see how these changes affect the simulation.