Scratch for Kids

A Watch the course on Frontend Masters

Using Colors To Sense Direction

Weā€™ve using the Sensing blocks to detect if we should stop falling, but this doesnā€™t work super well with a platformer because we donā€™t want our player to stop falling because their head is touching the platform. (Or, maybe you do. I donā€™t know.)

In Scratch, we donā€™t have a ton of options, but there is a little trick that we can use: the ability to see if a certain color on the sprite is touching another color.

If weā€™re super careful about our color choices, we can get the mechanic that weā€™re looking for.

if <color (#F00) is touching (#00F)?> then
	set [y velocity v] to [0]
end

If weā€™re clever, we can also use colors to detect if we touching a wall as well. But, Iā€™ll leave that as an exercise for you.