In this tutorial, we introduce you to scripting in Amazon Sumerian. You will add a script that will cause a sphere to move back and forth.
You’ll learn about:
- Adding a script to an entity
- Move an entity by using a script
- Script Editor
This is the scene we will build in this tutorial. For best results, be sure you are using the latest version of your browser.
You should have completed the following tasks and tutorials:
- Sign in to Amazon Sumerian with your AWS account
- Amazon Sumerian Interface tutorial
- Sumerian Basics: Creating a TV Room
- Visit the Scripting section in the Amazon Sumerian User Guide
- See the Amazon Sumerian Scripting API Reference
What Is Scripting?
Step 1: Create a Scene and Add a Sphere
From the Dashboard, create a new scene using the Default Lighting scene.
From the Create Entity menu, choose a Sphere entity.
Step 2: Add a Script Component and Add a Script to the Sphere
In the Inspector panel, choose Add Component, and then select Script.
You can see a new Script component tab in the Inspector panel. To add a script to the Script component, click the + button.
You are shown several preset scripts. However, for this tutorial, we want to write our own script. Choose Custom.
In the Script component, click the edit button (pencil icon) next to the script that you just created. The Script Editor opens.
Step 3: Add Some Code to the Script
The script has three functions in it: setup, update, and cleanup. For our simple script, we only need to worry about the update function. This function is called on every render frame, which is perfect for a simple animation.
- Copy the following code into the update function:
ctx.entity.transformComponent.setTranslation(Math.sin(ctx.world.time), 0, 0);
This line of code sets the X position of the sphere to the sine of the current time. This value will oscillate between -1 and 1 as time goes by, making the sphere entity move back and forth.
Click Save in the Script Editor to save the update.