Rolling Objects By Rui Batista
Sometimes we have to deal with dynamically driven movements but three things can happen that prevent us from doing it:
Tutorial
1. We don't own the Dynamics module 2. Dynamics are just too slow to calculate or 3. Adjusting Dynamics parameters is just too complex and time consuming. So, what do we do? We fake it! In this article we will see how to, automatically, place an object above the floor, no matter what orientation it has. I will present two methods: a simpler, not very accurate method and a more complex, but much more accurate method. The first method uses only XPresso and is best suited for objects that are roughly spherical in shape. For example, this apple is mainly spherical [01].
Image 02
between the center of the apple and the point where the "ray" hits the surface is the distance that the apple must rise from the ground. This works most of the time (example #1 and #2) but sometimes it fails miserably (example #3). Even so, for simple objects this is good enough method. Let me explain how to "code" it in XPresso. Instead of an apple, create a simpler object. For example, an egg (its simple enough to model). It doesn't have to be a polygonal object so, you can use a Lathe NURBS if you want. Let’s name it Egg_Mesh from now on. Make sure the axis of the Egg_Mesh object is placed where you consider to be the center. Now, clone Egg_Mesh, name it Egg_Dummy and place them both inside a Null. Make sure they are centered in the Null (their coordinates are 0,0,0). Now make the Egg_Dummy invisible both at the editor and to the renderer. You should end up with a hierarchy similar to figure [03].
Image 01
What the XPresso expression will do is to calculate the interception, on the object mesh of a ray that passes through the middle of that object and a point that lies precisely beneath it some distance apart. This may sound too complicated, but check out image [02], Example #1. A "ray" is sent from the center of the apple to a point beneath it (a safe distance away to assure it lays outside of the apple). The distance
Image 03
Add an XPresso tag to the Egg_Dummy object. Drag into the XPresso window, both Egg_Mesh
42
and Egg_Dummy. Now, create a Global Rotation port as an output of Egg_Mesh and a Global Rotation port as an input of Egg_Dummy. Connect them. From now on, when you rotate the Egg_Mesh, the Egg_Dummy object will rotate the same way. Duplicate the Egg_Dummy node and delete the Global Rotation port. Add it an Object port and a Global Position port as an output. Now, we must subtract a distance from the Y component of the coordinates. So, create a Vector2Reals node and feed the Global Position from the Egg_Dummy into it. Create a Reals2Vector node and connect to it the X and Z values from the Vector2Reals node. This is because we only need to manipulate the Y coordinate. Create a Math node and set it to Subtract. Feed the Y coordinate from the Vector2Reals into the Math node and connect the output of the Math node to the Y coordinate of the Reals2Vector node. Now, how much to subtract from the Y coordinate? I set it to 1000, but you can input any large number. Just make sure it is a number larger than the radius of the imaginary sphere around your object. [04] Now, add a Ray Collision node. Feed it the Object port from the Egg_Dummy, the Global Position port from the Egg_Dummy on the