Mastering Game Physics: Adding Gravity and Collision Detection in MakeCode Arcade

Kiki Prottsman
Kiki’s Corner
Published in
2 min readJun 12, 2023

--

Do you like to bump into things? Do you think it’s more exciting to jump & fall than to hover? In this post, we’ll explore the fascinating realm of physics within Microsoft MakeCode Arcade and how you can master game physics to create interesting and interactive games.

Strap in and get ready to learn about gravity and collision detection!

Physics in Video Games

“Game physics” refers to the rules and behaviors that govern objects within a game world. It determines how objects move, collide, and interact with each other. In Microsoft MakeCode Arcade, you can utilize the principles of physics to make your games more realistic and exciting. Let’s look at two aspects of game physics: gravity and collision detection.

The Force of Gravity

Gravity is a fundamental force that pulls objects toward the ground. In MakeCode Arcade, you can simulate gravity by adding acceleration to a sprite along the vertical (ay) to create a realistic sense of weight and motion.

By applying different amounts of vertical acceleration to your game characters, they can fall down, float up, and move as if affected by gravity.

Experiment with different ay values to achieve your desired effect.

Remember, stronger gravity makes objects fall faster, while weaker gravity creates a slower descent, and negative gravity creates floating or flying.

Detecting Collisions

Collision detection is how the computer determines when two objects come into contact with each other. In MakeCode Arcade, you can implement collision detection through an overlap event to create interactive and responsive games. For example, you can check if a player’s character touches a wall, an enemy, or a collectible item.

When collisions occur, you can trigger specific actions, such as reducing the player’s health or increasing their score. By detecting collisions accurately, you can add exciting challenges and obstacles to your games.

Here, the program detects when the player overlaps the purple tile and it declares the game won

Conclusion

Mastering game physics in MakeCode Arcade unlocks a realm of creativity and interactivity in your game design. By understanding gravity and collision detection — and how to apply them — you can create captivating games that dazzle players.

--

--

Kiki Prottsman
Kiki’s Corner

Kiki is an author, educator, and the Director of Education for Microsoft MakeCode