Thanks for playing! We record the motion of the mouse over the last 1.2 seconds and use that information to calculate the mouse's average position and speed. The average position of the mouse determines the direction in which the lasso will be thrown, and the average speed of the mouse determines how far it will go.
Every frame, we add a struct with the current game time, mouse position, and mouse speed to a List. We calculate the mouse speed by getting the vector between the mouse's current position and its position last frame, calculating that vector's magnitude, and dividing that magnitude by TIme.deltaTime. (speed = distance/time)
So we have a list with a bunch of structs that have a timestamp, the mouse position at the given time, and the mouse speed at that time. We then loop through the structs in that list to calculate the average position and speed of the mouse. When looping through the list, we skip and remove any items that were added over 1.2 seconds ago (by comparing to the current game time), then sum up the rest and divide by the number of things we summed together. That gives us the average position and speed of the mouse over the last 1.2 seconds.
We use Camera.main.ScreenToWorldPoint to convert the average position of the mouse from screen space (where it is on your screen in pixels) to world space (where it is in the physical game world compared to other GameObjects). The lasso is thrown from the player towards that point, and the final distance it travels is scaled by the average mouse speed we calculated.
When the player releases the mouse, any cows within a certain distance of that final position are captured.
Hopefully my explanation wasn't too confusing!