Cinema 4D / BodyPaint 3D Program Documentation Tutorials XPresso Tutorial
Function available in CINEMA 4D Prime, Visualize, Broadcast, Studio & BodyPaint 3D

Mixed Alignment to Two Targets

In the previous tutorial we created a simple alignment using XPresso. This tutorial showed us that matrices are not as complicated to work with as we may have thought. Nevertheless, this Expression is one that could also have been created using a standard Alignment tag.

In this tutorial we will take XPresso a step further and will expand the Expression a bit. Our goal is to mix two alignments of the eye to two target objects. This will let the eye’s angle of view be moved in a realistic motion between two target objects.

Additional User Data

First, open the file with the Expression from the previous tutorial:

Select the XPresso tag and then the Manage User Data option from the Attribute Manager’s User Data.

In the window that opens, select "Target" and rename it "Target 1".

Click on the Add Data button to add another User Data item. Name this new item "Target 2" and set its Data Type to Link.

We now have two separate targets that can be defined. What we need now is a slider that we can use to adjust the mixing of the alignment between the two targets.

Add another item and name it "Mix". Set its Interface option to Float Slider and click on OK to close the Manager User Data window. Now double-click on the XPresso tag in the Object Manager to open the XPresso Editor window.

Adjusting the Expression

Create output Ports for the XPresso Node’s User Data items Target 2 and Mix.

As for the first target object we also need an Object Node for the second target object in order to get access to the object’s Global Position. Create a new Object Node (XPresso/General). The name of the node is also Eye because the XPresso tag is assigned to the Eye object. As already explained above, this is completely irrelavant but to better distinguish the elements we will correct the naming as soon as the second Target object has been created.

Of course this Node also requires an Object input Port, which we will connect with the XPresso Object Node’s Target 2 output Port, as well as a Global Position output Port (Coordinates/Global Position). Remove the connection between the first Object Node and the Math Node. Since our Expression is increasing in size we will have to reposition the individual Nodes to make sure they are all visible in the XPresso Editor window.

Next we will mix the positions of both target objects. To do so we will create a new Mix Node (XPresso/Calculate). In the Attribute Manager, set this Node’s Data Type to Vector. Now connect the input Port Input 1 with the Global Position output Port of the Object Node connected with the "Target 1" User Data output Port; connect the input Port Input 2 with the output Port of the Object Node connected with the "Target 2" User Data output Port. Next, connect the Mixing Factor input Port with the XPresso Node’s Mix output Port. Finally, connect the Mix Node’s output Port with the Math Node’s input Port.

We can now close the XPresso Editor window. Now create copy of the existing "Target" object in the Object Manager and name the copy "Target 2". Rename the original "Target" object "Target 1".

If we now select the XPresso tag the User Data will be displayed in the Attribute Manager. Drag the new target object "Target 2" into the Link field "Link 2".

If we now position each target object at different locations in the scene and use the "Mix" slider to adjust the alignment we can move the eye’s angle of view back-and-forth from one target object to the other.