May 5, 2017
11623 Views
6 0

Coding with CoSpaces: Activating Objects

Written by

Interested in teaching coding? You can now code in Blockly or in Javascript.  Many powerful experiences can be created. In this simple tutorial, I will show you how to activate objects — in other words, whenever you touch or click on something, to have it execute some code.

Estimated Time: 15 minutes
Difficulty: Easy

Getting Started

  1. Create an account or login to CoSpaces.
  2. Create a new Space.
  3. In the upper right hand corner, click on the Code icon.

cospaces

This will open up a Code panel where you can enter in custom code.  You have two choices — Javascript or Blockly.

cospaces coding

We can do all sorts of things in CoSpaces.  In this simple example, we’ll move a person whenever someone touches him or clicks on him.  We drag and drop a person from the Library onto the Scene.  Then we need to assign it with a name.  Click on the icon that looks like a tag and type in a name.  In the example below, I used the name redperson. Hit enter to save the name.  We can use this name in our code now.

In this coding example, we’ll use the Blockly scripting language (an easy to understand drag-and-drop coding interface).  Click on the Blockly tab in the Code panel.

We can now drag and drop various puzzle shaped coding blocks.  In the Events section, I’ll drag the “on activate of” block.

coding example

“On Activate of..” is an Event that waits for something to activate (or touch/click on) an object.  We’ll make it so that whenever the redperson is activated, he will move.  Drag and drop the “move” block and snap it to fit inside the green block.

In this example, the redperson will move one meter forward in one second.

Press the Play icon in the top right.  Click on the redperson.  He moves forward.  Feel free to explore other possibilities using Blockly (or Javascript code!)

Article Tags:
· ·
Article Categories:
Coding · Tutorials · Virtual Reality


Leave a Comment

Your email address will not be published. Required fields are marked *