how to make collision in scratch

How To Make Collision in Scratch

By Anthony Martinez
AD

In the dynamic world of Scratch, making collisions between sprites is a fundamental part of creating engaging games and animations. This concept allows your sprites to interact with each other, providing realistic feedback and enhancing the overall user experience. Here, we'll explore how to make collisions in Scratch in a comprehensive yet easy-to-understand manner, ensuring you're equipped to bring your creative ideas to life.

Before we delve into the steps, it's crucial to understand that in Scratch, collision detection between sprites is automatic. However, to make the most of this feature, you need to know how to trigger scripts based on collisions. Additionally, understanding the types of collisions will help you create more advanced projects. Let's dive right in!

Understanding Collisions in Scratch

Scratch supports two types of collisions: touching and meeting. Both have their unique use cases, and being familiar with them will help you make the most of this feature.

AD
How to Make a Platformer with Ground Detection in Scratch | Platformer Tutorial Part 2
How to Make a Platformer with Ground Detection in Scratch | Platformer Tutorial Part 2
Build a Space Invaders Game in Scratch 3.0 | Free Coding Tutorial ⭐
Build a Space Invaders Game in Scratch 3.0 | Free Coding Tutorial ⭐
How to Make Many Bouncing Balls in Scratch
How to Make Many Bouncing Balls in Scratch

The 'touching' collision occurs when the edges of two sprites cover each other entirely. This type of collision is ideal for creating impactful effects and sending sprites to specific positions upon contact. In contrast, the 'meeting' collision happens when the edges of two sprites start to cover each other. This type is useful for creating ongoing interactions, like sound effects or animation changes, over time.

Touching Collisions

To create a 'touching' collision, you'll need to use the 'touching' object sensor. Here's how to do it:

How to Make a Ball Bounce in Scratch - Create & Learn
How to Make a Ball Bounce in Scratch - Create & Learn
Catch the Falling Fruit Game in Scratch | Easy Scratch Game Tutorial by Kodex Academy
Catch the Falling Fruit Game in Scratch | Easy Scratch Game Tutorial by Kodex Academy
Let's Build: How to Make Amazing Mazes Game in Scratch - Part 2
Let's Build: How to Make Amazing Mazes Game in Scratch - Part 2

1. Click on the 'Events' category in the_blocks palette and drag the 'when touching [Sprite Name] happens' block to your sprite's script area. Replace '[Sprite Name]' with the name of the sprite you want your sprite to collide with.

2. Now, you can add various other blocks to perform actions when the collision occurs. For example, you can use 'change [X position] by [#]' or 'say [ message] for [#] secs' to create an instant or ongoing reaction.

AD

Meeting Collisions

Creating a 'meeting' collision involves using the 'meeting' object sensor. Follow these steps:

How to Make Your Sprite Move in Scratch Using Arrow Keys or WASD
How to Make Your Sprite Move in Scratch Using Arrow Keys or WASD
How To Make A Basketball Game On Scratch
How To Make A Basketball Game On Scratch
How to Make a Zombie Survival Game in Scratch!!!
How to Make a Zombie Survival Game in Scratch!!!
Scratch Idle Bouncing Ball Game
Scratch Idle Bouncing Ball Game
a computer screen with an animated game on it's display area and the texting options displayed
a computer screen with an animated game on it's display area and the texting options displayed
How to Make a Virtual Pet in Scratch | Tutorial
How to Make a Virtual Pet in Scratch | Tutorial

1. Similar to touching collisions, start by selecting 'when meeting [Sprite Name] happens' from the 'Events' category and adding it to your sprite's script area. Replace '[Sprite Name]' with the target sprite.

2. Add desired blocks to the script. Since meeting collisions occur over time, consider using blocks like 'point in direction [Sprite Name]' or 'change costume to [costume]' to create progressive effects.

AD

Manipulating Collisions with Costumes

Changing costumes in response to collisions adds another layer of interactivity to your projects. Here's how you can do it:

Scratch Collision Detection: Halloween Conditional Coding Activity - Our Family Code
Scratch Collision Detection: Halloween Conditional Coding Activity - Our Family Code
Cómo hacer un juego de plataformas en scratch
Cómo hacer un juego de plataformas en scratch
How to Make a Geometry Dash Game on Scratch - Create & Learn
How to Make a Geometry Dash Game on Scratch - Create & Learn

1. Open the'inspectorArea' for the sprite that will change costumes, and click on the 'Events' tab.

2. Click on the 'when [Event] happens' dropdown and select either 'touching [Sprite Name]' or 'meeting [Sprite Name]', depending on your desired collision effect.

AD

3. Now, click on thecriptsArea', and then click on the 'Looks' tab.

4. Drag the 'change costume to [costume name]' block into the script area and select the desired costume from the dropdown menu.

Creating Custom Collision Blocks

If you want more control over your collisions, you can create custom collision blocks using the blocks 'when I receive [message{v1}]' and 'broadcast [message{v1}] and wait'. Here's how:

1. In the 'Looks' category, use 'broadcast [message{v1}] and wait' to create a collision message with a unique name, like 'collision with [Sprite Name]'.

2. On the target sprite, use the 'when I receive [message{v1}]' block in the 'Events' category to catch the broadcast and perform desired actions.

Custom collision blocks allow for more complex interactions and better organization of your scripts, especially in larger projects.

As you've seen, making collisions in Scratch is an essential skill that unlocks a world of interactive possibilities. Whether you're creating a simple game, an engaging animation, or intricate simulations, understanding and mastering collisions will take your projects to the next level. Keep experimenting, and embrace the iterative spirit of coding. Happy Scratching!

AD