Meet Emilio! He’s teamed up with instructor Zack as part of Game-U’s New Jersey Accelerate program, and he’s got his own way to beat the summer heat. Using the Brain, or code center, of a prop in the 3D game editor Project Spark, Emilio programmed a snowball player that impacts and responds to its wintry environment. Check out Emilio’s snowball effect!
What happens when you roll a snowball across more snow? The snowball grows, of course! Emilio swapped out the mesh, or skin, of his default player character (nicknamed Flynn for his resemblance to the Tangled character Flynn Rider) for a primitive sphere object. Once inside the object’s Brain, Emilio brainstormed the snowball code by asking himself a few questions about the growing behavior he wanted to create. What incident or event should trigger the behavior? Which of the snowball’s properties needed to change in response to the trigger? To answer those questions, Emilio looked at a real snowball. It grows when it comes into contact with more snow, and as it grows, its scale increases. So in the “When,” side of his program, Emilio used the “Bump Terrain” tile and a specific terrain material tile, and in the “Do,” side of his program, he identified the snowball’s scale property and coded it to increment by a certain value. Now, when the snowball bumps terrain painted with that material, the snowball’s scale increases!
Next, Emilio looked at what should happen when the snowball comes into contact with another object. He applied the same event-action, logical thinking process to figure out what code tiles should be added to the “When,” and “Do,” sides of his program. What happens when a snowball comes into contact with another object? Well, in the real world, as long as the snowball is big enough, the object usually gets picked up along with the snow. To replicate this behavior with code, Emilio decided to add several conditions to the “attach” action. If the snowball’s scale is greater than 2, if it bumps another object, and if that object is not the player, any code controlling the bumped object should be turned off (deactivated) and the object should be attached to the snowball. When all three conditions are met, the action code is triggered and the bumped object becomes part of the snowball!
Awesome mechanics on display here, Emilio! Thanks for sharing your code with us. You may be using code tiles now, but the logic you’re learning applies to programming languages everywhere, even Java or C#. Keep up the good work! We’re excited to see all the cool things you’ll code.