I made this just to see if I could recreate Withered Foxy's AI from FNaF 2 on Scratch. -INSTRUCTIONS- You can change his AI level from 0 to 17 (His AI is capped at 17 in the actual game) The upper counter is the variable 'D' value, which basically increases every second, but if Foxy is in the hallway, and you shine the light [space], it will reset to 0). Every 5 seconds, the D value is subtracted from a number (20+(4)), which is then compared to his AI level. If the number is less than or equal to the AI, he will move. The lower counter is the variable 'J' value, which measures how long you have had your flashlight on Foxy. Once it reaches a certain value, 300 in this case, he will retreat to his starting position. If he has a successful movement while in the hallway, he kills you.
Scott Cawthon - FNaF