# Unit 3, Lesson 15 8F HELP Needed

A student created this.

She wanted “fanged_face2” to move to the center, then back to the original place. Can you tell me why it didn’t work, and how we can fix it?

Sheila

So, what is happening here is that the first code for moving fanged_face2 is running with every pass through the draw loop. So, once he gets to the center, your conditional tells it to move back to the starting point, but the next time through the loop, the original code tells him to move towards the opposite corner. Then the conditional kicks in and although you can’t really see it, it is going back and forth one pixel at a time giving the appearance of being stuck in the center.

One way to solve this would be with a boolean variable. For example, if I start and create a variable called “forward” and set it to true, I could have a conditional in my code saying "if forward = true,
Then
fanged_face2.x=fanged_face2.x-1 && fanged_face2.y=fanged_face.2-1
ELSE
fanged_face2.x=fanged_face2.x + 1 && fanged_face2.y = fanged_face2.y+1

Then your original conditional is used to change the direction variable. If the sprite.x is less than 200, change the variable “forward” to be false.

There are probably other ways to make it work as well.

Check back in if you still have problems with it.

Mike

Thank you. I don’t think I followed your directions correctly, so I’ll keep trying. I think I understand the logic.

Ok… you’ll probably understand it better if you get it on your own, but if you want the working solution, I was able to get it to work and I can share with you.

Mike