
Sometimes (like we will see at our demo) is important the capture of the collision of a part of an object, because sometimes each part will create a different reaction.
Better if you play our demo first. Pay attention: the collision of the "yellow lights" starts a reation different than the collision of the "orange lights".
Squeak has a very useful method (its curious name is : sees ) that captures (returns: true) the collision of two colors! So: all we need to do is to paint the part of an object with some color and compare if we have the collision of this "color" against the "color" of another object (or part of object).
In this case, to create the block of code IF-THEN-ELSE is better to use the "visual programming" technique. Look, in the figure how we drag a block of test inside a script:
And you need to open the part of the Viewer whose name is: tests (clicking in the name of any part and choosing in the menu). Drag, like you see in the figure the line: "Trucks color sees" to the line having the word: "Test"; over a little green retangle (sometimes it's not easy to do this...).
You will see in this line of code two little retangles having colors. Click over each color and you will have a "picker" to click over each color you need to compare. Capture this colors in the objects, not in the general window of colors!
In the line having the word "Yes": put what you like to do if there are the collision of this two colors.
At our demo we have 2 tests. In the first, if the front of the truck collides against the pavement, we move the truck forward: - 5 (back).Try to understand the second test.
You need to put this script "ticking" (using the menu after the clock) - in loop!
PREVIOUS LESSON NEXT LESSON T. CONTENTS HOMEPAGE
