Jan 11, 2019
2 3

CoSpaces tutorial – Quick programming to make an object move

Written by

Recently, CoSpaces made the move away from Blockly and is now using their own visual coding language called CoBlocks. As are most visual coding languages, CoBlocks is pretty intuitive and if you already know Blockly, is very easy to use. In this beginner-level tutorial, we will learn how to program an object to move by itself, without any interaction by the user. You can also see the faint outline of the camera, where the users point of view will begin.


Estimated Time: 10 minutes
Difficulty: Easy

  1. Create on object in your CoSpace environment. In this particular example, I have a few objects, a rainbow, a pink unicorn, a rabbit, and a diamond.

2. Then double-click on your new object and a menu should pop up that looks like this.

3. Click on the “Code” symbol in the top left spot in the menu and activate the “Use in CoBlocks” option. Now you can access this object with the programming languages in CoSpaces.

4. Next, look at the header in the CoSpaces workspace and you should see a “Code” symbol in the upper right hand corner. Click on it and you will see a split window with your workspace on the left and the coding space on the right. You can adjust the width of these windows by clicking on and dragging the middle border line.


5. In the coding window, it first gives you a choice of which coding language to use. For now, choose “CoBlocks”. It starts you off with the “When Play clicked” block already out there. This simply means that whatever blocks of code you place connected to the bottom of this block will initiate once Play is clicked. To find the different blocks of code you can use, click on one of the spaces in the coding window’s left-side column. They should be labeled “Transform”, “Actions”, etc.


6. To make an object move, you simply click and drag the first block that says “move” and place it directly below (connected) to the yellow “When Play clicked” block. Now my screen looks like this.

7. First, ignore my coding windows extra tabs that say “Blockly…”. Those are remnants of previous code we don’t need. Notice my Move block defaults to my Rainbow object moving 1 meter forward in 1 sec. We want this to move my unicorn, whose name is  “Twilight Sparkle”,  in the upward direction. You can choose whatever values you want for the meters, direction, and sec. I chose 3 meters, up, and 2 secs. My code looks like this now.

8. That’s it! Now to see your automatically moving object (unicorn in my case) just hit Play in the CoSpaces header! Some notes about programming in CoBlocks:

  • The blocks of code will be run sequentially based on how you order them (beginning from the top to the bottom). Although there are some blocks that allow for “waiting” or “parallel running” to occur.
  • To create another function or code another object to do something else, create another CoBlocks window by pressing the plus (+) button next to the blue “CoBlocks” tab.
  • You can rename each CoBlocks window for easier identification of the code’s purpose by double-clicking on the blue “CoBlocks” name tab.

9. In case you are interested in using Javascript as your coding language in CoSpaces, a very helpful tool is the CoSpaces Javascript API webpage. This gives you all of the methods and functions (with examples) that can be used in CoSpaces. For example, to create a house, scale it to a larger size, and move it automatically, you can use this simple code in the “Script” option in the CoSpaces coding window:

let house: BaseItem = Scene.createItem('LP_House', 2, 2, 0);


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

Leave a Comment

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