Knowledge Base - Using the Library

Notice: This article builds upon the visual script created in the Your First Visual Script article.

In this article, you will learn the four (4) methods of accessing the library content. In doing so, you will update the sphere movement created in the previous article to orbit the world center (0,0,0) using simple mathematical function nodes.

Starting from Your First Visual Script example, perform the following steps:

1- Method #1: Using the Instance Wizard

The Instance Wizard give you access to the variables and operations available on a specific class of object instance. You will use the Instance Wizard to remove the Translate(…) function and add the set_position property of the Transform component attached to the sphere.

In the visual editor, select the Transform node to activate the Instance Wizard.

In the operations section of the Instance Wizard, scroll to and click the highlighted Translate(x:float, y:float, z:float) to remove it from the Transform.

In the variables section of the Instance Wizard, click the input checkbox of the position property to expose it.

2- Method #2: Browsing the Library Content

The sinus and cosinus functions will be used to orbit the sphere around (0,0,0). These functions will be extracted from the Mathf class included in the Unity Engine assembly.

To add the sin function:

  1. In the Library Panel, open the Unity top level icon then the UnityEngine package;
  2. Scroll until you see the Mathf class;
  3. Drag the Sin(f:float)->:float from under Mathf into the Visual Editor to create the Sin function node.

3- Method #3: Searching the Library Content

Adding the cos function:

  1. Enter the word “cos” in the search field in the Library Panel;
  2. Drag the Cos(f:float)->:float item from the library panel into the Visual Editor to create the Cos function node.

4- Method #4: Contextual Library Menu

The Sin and Cos mathematical nodes produce separate floating point values. These values must be collated in a :Vector3 type to be bound with the position property of the Transform.

Creating the ToVector3(x:float, y:float, z:float) adaptor node:

  1. Drag and release the position port of the Transform inside the Update node;
  2. From the contextual menu, select iCanScript | From<->To | FromTo | ToVector(x:float, y:float, z:float)->:Vector3 to add the node.

Cleanup and bind the nodes:

  1. Drag the nodes from the title bar to reposition them;
  2. Bind the Sin output port to the x input of the ToVector node;
  3. Bind the Cos output port to the z input of the ToVector node.

5- Complete the Visual Script

To complete your script, you need to drive the input port of the Sin and Cos nodes with a time base function.

  1. Search for “realtime” in the Library panel;
  2. Drag the realtimeSinceStartup function into the Update node;
  3. Bind the output port of the realtimeSinceStartup node to the input ports of both the Sin and Cos nodes.

6- Run the Visual Script

The script is complete and can be ran by pressing the play button. The sphere orbits the position (0,0,0) with a radius of 1.

7- What Have You Learned?

  1. Remove the translate function using the Instance Wizard;
  2. Add the set position property using the Instance Wizard;
  3. Add the Sin(…) function by browsing the library;
  4. Add the Cos(…) function by searching the library;
  5. Add the ToVector(…) function using the library contextual menu triggered by dragging a port out in the open.

Details

Created : 2015-03-16 15:16:36, Last Modified : 2015-03-16 15:16:36

User Comments

Add a Comment

http://undeclaiming.xyz norsk kasino http://undeclaiming.xyz - norsk kasino SailipHogue, http://undeclaiming.xyz @ 2017-05-03, 11:59

Search Articles

Member Login