Unit 3 Lesson 22 change "crash" sprite

Hi all!
I have a student who is working on the final project in Unit 3. He wants the “cone” sprite to temporarily change to “cone2” sprite when the car hits the cone. Then continue again as “cone,” until it hits again, etc.

Can anyone help?

Hi @sfredericks,

When you try the most simple solution, to change the setAnimation of the cone in the “car.isTouching(cone)” code, because the reset function immediately moves the cone, the cone doesn’t remain as cone2 for long.

So, you would need to create a timer that states if the time is less than the desired amount, the cone is the cone2. If it is greater than the desired amount, it is the regular cone animation. There are many ways to create a timer. I think the easiest is:
myTimer = myTimer+1/30

I hope I understood the question and started you on the right path. It is a fun (and addicting!!) game!!

Update: Mike was working on this…his great response is below.


1 Like

This was a little trickier than I thought it would be. It is difficult to “time” something in Game Lab because of the way Game Lab is built. There is a built in block called “WorldSeconds” that tells how much time has lapsed since the game started and I first tried to create a new “collision” variable right when the collision occurred and then tried to use that to change the costume for a certain number of seconds, but everything I tried after that didn’t quite have the desired effect.

So, the best I can come up with off the top of my head is to create a new sprite called “cone2” with the costume of the crashed cone (cone2) and start it off the screen where it can’t be seen. Then, when the collision happens, before calling the function setCone() I called a new function called crashCone(). In that function, I set the x and y value of cone2 to be the same x and y value of cone1 and set its velocityY to match cone1 (4). Then, the setCone() function is called (just as it is now) to reset the original cone. The only thing I changed is that I started the new cone in the setCone function at cone.y=-300 so it was higher off the screen giving cone2 a little longer to exit the screen before the new cone starts its way down the screen.

I know there are smarter people than me out there that may have a more creative way, so if so, please chime in!

Let us know if your student has any problems implementing that or any other issues!



1 Like

Thank you! I’ve forwarded this to my student to see if he can do it. I will try over the weekend, as well!