hiya! Javascript has a function named setInterval (https://developer.mozilla.org/en-US/docs/Web/API/Window/setInterval) which lets you set a function to be called at some arbitrary regular time increment! I then used that to make a tick loop to move things around every couple milliseconds!
oh yea Ik you'd use setInterval to write JS timer function, I mean how did you write for the dropping food anywhere on the page so one of your fishes flips itself and goes eat it part?
hiii sorry i missed your reply! So the way i handled it was like this:
fish idle by randomly picking a point on the screen, and a duration to get there, then lerping to reach it.
When you click on the screen, it registers the location that you clicked on (like the screen x and y), and constructs a Food object which is then put into an array
When a fish goes to pick its new random point, if there is food in the array, then it pops the food off of the array, and sets *that* as its next point instead!
Once it reaches the position, it deletes the food and goes back to idling!
hiya! Javascript has a function named setInterval (https://developer.mozilla.org/en-US/docs/Web/API/Window/setInterval) which lets you set a function to be called at some arbitrary regular time increment! I then used that to make a tick loop to move things around every couple milliseconds!
oh yea Ik you'd use setInterval to write JS timer function, I mean how did you write for the dropping food anywhere on the page so one of your fishes flips itself and goes eat it part?
hiii sorry i missed your reply! So the way i handled it was like this: fish idle by randomly picking a point on the screen, and a duration to get there, then lerping to reach it. When you click on the screen, it registers the location that you clicked on (like the screen x and y), and constructs a Food object which is then put into an array
When a fish goes to pick its new random point, if there is food in the array, then it pops the food off of the array, and sets *that* as its next point instead! Once it reaches the position, it deletes the food and goes back to idling!