Tap to pick closest object: Difference between revisions
-u ndefined- (talk | contribs) (Created page with "So many games involve tapping very small objects on the screen. But phones are small, fingers are big, and people's patience is limited. So many games are so much fun if they're kind to the player. If they hastily tapped in the general vicinity, but missed by a pixel? Give them a break and pretend they hit perfectly! Here's Martin's favorite way to turn that kindness into script: {{Image|Tap_to_pick_closest_object.png}} First, the three tappable wood blocks add thems...") |
(link to Object) Tags: Mobile edit Mobile web edit Advanced mobile edit |
||
Line 1: | Line 1: | ||
So many games involve tapping very small | So many games involve tapping very small [[object]]s on the screen. But phones are small, fingers are big, and people's patience is limited. | ||
So many games are so much fun if they're kind to the player. | So many games are so much fun if they're kind to the player. | ||
If they hastily tapped in the general vicinity, but missed by a pixel? | If they hastily tapped in the general vicinity, but missed by a pixel? |
Latest revision as of 14:17, 23 August 2025
So many games involve tapping very small objects on the screen. But phones are small, fingers are big, and people's patience is limited. So many games are so much fun if they're kind to the player. If they hastily tapped in the general vicinity, but missed by a pixel? Give them a break and pretend they hit perfectly!
Here's Martin's favorite way to turn that kindness into script:

First, the three tappable wood blocks add themselves to a list named $Bs
. (Short for Blocks
.) Then our Touch Sensor feeds into Line vs Plane to compute the world coordinate the player tapped.
Our loop then checks the distance between our finger and the position of all blocks in the list, and keeps track of the best pick.
Finally, do whatever you want with the tapped object, e.g. Set Position moves it to the tap position.
In this example Best
is initialized to 3, so even if the tap misses by a large margin, it'll still count as a hit!
And if multiple objects are within that distance, it'll still pick the best hit.