FUN2.3 Coding

FUN2.3 Coding
Responsive Google Slides
Check Your Understanding Quiz

Optional Quiz – These questions will help you prepare for the final quiz, where the course content will be locked.

View Transcript

Slide 4 – Firstly, make sure the object that you want to apply code to is enabled for CoBlocks coding.

Then to access the coding dashboard, click on ‘code’ in the top right-hand corner and choose ‘CoBlocks’. On the left of the dashboard, you will find various coding blocks for programming. In the ‘transform’ section, you will find coding blocks used for object movement. In the ‘action’ section, you will find coding blocks used to make objects talk, add sound, video and other interactive elements to your world. In the ‘event’ section, you will find coding blocks used to track user input and object collision. In the ‘control’ section, you will find coding blocks containing loop and if statements and other functions used to control your world such as blocks used as timers and to switch and restart scenes. In the ‘operators’ section, you will find coding blocks used to control arithmetic functions and random integer selection. In the ‘items’ section, you will find coding blocks used for item modification functionality such as deleting objects. In the ‘data’ section, you will find coding blocks used to set and modify variables. If you do not have advanced CoBlocks enabled, there will be no coding blocks in the ‘functions’ section. If you have advanced CoBlocks enabled in the CoBlocks settings, you will have access to more coding blocks and a menu for physics will appear. However, since we are just starting out, there is no need to worry about advanced CoBlocks just yet. To utilise a coding block, click or press on the block you want to use and then drag it into the script. For example, if you want your object to move forward, you can use one of the move blocks from the transform section. You will then have the ability to modify aspects such as which object will be moved and how far, which direction, and how fast it will move. To test your code, click on ‘Play’ on the upper right hand corner.

Slide 11 – Firstly, drag a girl model and a horse model in your world. Set the animation of the girl to ‘Ride Horse’, then attach the girl to the top of the horse to make it look like she is riding the horse.

Now enable the horse to be coded with CoBlocks and enter the coding dashboard. In the Transform section, drag the first movement block into the script. In the dropdown menu, select horse as the item to be moved and set it to move 5 metres forward in 3 seconds. If we hit Play, we can see that the horse will do as we instruct it. However, it lifelessly floats forward and doesn’t actually move its legs or body. To fix this, let’s head back into the coding dashboard. Go into the action section and drag in two animation blocks, one above and one below the move block. We are now going to set the first block to animate the horse trotting, and the second one to animate the horse in a neutral state. Please note that animation coding is only available in the Pro Version of CoSpaces. Now if we press Play, the horse will look more alive since it appears to be trotting forwards. Now we are going to code the horse to move along a set path. A path allows us to make the horse change directions without having to use lots of coding blocks. Firstly go to the library tab and go to the special section. Here you will find three different path shapes, round, square and a line. Select and drag one of these paths into your world. You can adjust the shape of the path by moving the blue nodes. Once you’ve finished placing your path, go back to the CoBlocks dashboard, find the move on path coding block in the transform section and replace the current movement block with this. Choose horse as the object to move, the path you created as the path to move on, keep the direction as forward and set the speed to whatever you wish. Now if we press Play, the horse will move along the set path until it gets back to where it started. Let’s now go into the library, add a dog to the scene and enable it for CoBlocks programming. We going to program it to also move on the horse’s path to give the appears of chasing after the horse. As such, open up the CoBlocks dashboard. To make the horse run for longer, drag in a loop block from the control section and drag your preexisting code within it. Now to make the dog move on the path at the same time as the horse, we need to use the run parallel block under the control section. Drag your pre-existing code into the top section of the run parallel block. Now drag into the bottom section, the same CoBlocks used to make the horse run on the path and replicate the parameters with the exception of setting the object to be moved as a dog. Finally hit Play to watch your scene come to life.