{"author_link":"\/users\/adriangray","author_name":"AdrianGray","author_uid":"adriangray","comments":[],"epoch":1665138198,"event":"LD51","format":"md","ldjam_node_id":309373,"likes":4,"metadata":{"p_key":"169000","p_author":"AdrianGray","p_authorkey":"1300641","p_urlkey":"396759","p_title":"Unity WebGL mobile controls tips","p_cat":"LDJam ","p_event":"LD51","p_time":"1665138198","p_likes":"4","p_comments":"0","p_status":"WAYBACK","us_key":"1300641","us_name":"AdrianGray","us_username":"adriangray","event_start":"1664496000","event_key":"114","event_name":"Ludum Dare 51"},"node":{"_collation":{"body_sanitizer":"TextUtils::SanitizeHTML via existing importer","event":"LD51","removed_author":false},"_superparent":296586,"_trust":1,"author":300641,"body":"Hey,\n\nProbably many of you wanted to make mobile web controls for WebGL builds but encountered difficulties.\n\nHere are 2 walls I've hit and overcome with Unity builds.\n\nFirst there is a bug at least in the WebGL version of 2021.3.0f1 Unity that makes touch Stationary states non existent. \n\nSo it only reports Began until you move or lift the finger, then Moved.\n\nSo to overcome this just make a counter \"per finger\" (actually per zone, see in next section) that goes up on Moved or Began, resets to -1 when Ended or Canceled and before touch checks, it checks for -1 and sets it to 0 so you have a frame to check for -1 (Touch Up).\n\nThen you just check -1 for Touch Up, 0 for No Touch, 1 for First Touch and >0 for Touch Down.\n\nAll sounds good until you implement it based on finger ids.\n\nScreen tracking doesn't work so well as we feel it when using other apps.\nIf you hold one finger down and while pressing on other side of the screen  with another finger, lift the first finger you'll see that you get reported the same finger id but on another position.\n\n\nThis is not good for fast tapping games like Platformers.\n\nIn order to overcome this limitation you can introduce screen zones (basically bounds that checks if touches are inside).\n\nBecause we assume one finger should be one zone at one moment, we can use zone ids for controls instead of finger ids.\n\nSo to put it together all we do is:\n\nLoop through our touchCounts then inside loop througn our zones. If a touch position is inside our zone we apply the touch counter fix from above (depending on touch state we increment or reset the zone counter)\n\nDon't forget to treat no finger in zone as a TouchUp if it was down.\n\nGood luck and don't forget to check our game https:\/\/ldjam.com\/events\/ludum-dare\/51\/pandoras-box\n\nSee the itch.io link in description for Mobile web controls described here. ","comments":0,"created":"2022-10-07T10:09:26Z","files":[],"files-timestamp":0,"id":309373,"love":4,"love-timestamp":"2022-10-07T21:08:16Z","meta":[],"modified":"2022-10-07T21:08:16Z","name":"Unity WebGL mobile controls tips","node-timestamp":"2022-10-07T10:27:33Z","parent":304366,"parents":[1,5,9,296586,304366],"path":"\/events\/ludum-dare\/51\/pandoras-box\/unity-webgl-mobile-controls-tip","published":"2022-10-07T10:23:18Z","scope":"public","slug":"unity-webgl-mobile-controls-tip","subsubtype":"","subtype":"","type":"post","version":963885},"node_metadata":{"n_key":"309373","n_urlkey":"396759","n_parent":"304366","n_path":"\/events\/ludum-dare\/51\/pandoras-box\/unity-webgl-mobile-controls-tip","n_slug":"unity-webgl-mobile-controls-tip","n_type":"post","n_subtype":"","n_subsubtype":"","n_author":"300641","n_created":"1665137366","n_modified":"1665176896","n_version":"963885","n_status":"WAYBACK"},"source_url":"https:\/\/ldjam.com\/events\/ludum-dare\/51\/pandoras-box\/unity-webgl-mobile-controls-tip","text":"Hey,\n\nProbably many of you wanted to make mobile web controls for WebGL builds but encountered difficulties.\n\nHere are 2 walls I've hit and overcome with Unity builds.\n\nFirst there is a bug at least in the WebGL version of 2021.3.0f1 Unity that makes touch Stationary states non existent. \n\nSo it only reports Began until you move or lift the finger, then Moved.\n\nSo to overcome this just make a counter \"per finger\" (actually per zone, see in next section) that goes up on Moved or Began, resets to -1 when Ended or Canceled and before touch checks, it checks for -1 and sets it to 0 so you have a frame to check for -1 (Touch Up).\n\nThen you just check -1 for Touch Up, 0 for No Touch, 1 for First Touch and >0 for Touch Down.\n\nAll sounds good until you implement it based on finger ids.\n\nScreen tracking doesn't work so well as we feel it when using other apps.\nIf you hold one finger down and while pressing on other side of the screen  with another finger, lift the first finger you'll see that you get reported the same finger id but on another position.\n\n\nThis is not good for fast tapping games like Platformers.\n\nIn order to overcome this limitation you can introduce screen zones (basically bounds that checks if touches are inside).\n\nBecause we assume one finger should be one zone at one moment, we can use zone ids for controls instead of finger ids.\n\nSo to put it together all we do is:\n\nLoop through our touchCounts then inside loop througn our zones. If a touch position is inside our zone we apply the touch counter fix from above (depending on touch state we increment or reset the zone counter)\n\nDon't forget to treat no finger in zone as a TouchUp if it was down.\n\nGood luck and don't forget to check our game https:\/\/ldjam.com\/events\/ludum-dare\/51\/pandoras-box\n\nSee the itch.io link in description for Mobile web controls described here. ","title":"Unity WebGL mobile controls tips","wayback_source":[]}