Moving controls to the phone

oh lawd.
Spent ages trying to figure out how to change the pointer from following the mouse to following the touchscreen.

Then I found this and that.

Tried to get the pointers (made multiple of them, one for each possible number of touches) to work with multi-touch, causing many, many array exceptions, since the size of Input.touches[] changes based on how many touches it detects. And when that didn't work, attempting to formulate some way of using ray casts from the tapped position to check against the collision of the entities.

Then I found this.

The moral of this story? Search the documentation before you jump onto the internet looking for silly answers to simple solutions. Also to note, is that sometimes Unity Remote 4 will stop working with unity when you run it. This is fixed by restarting Unity, at least its worked for me when it does happen (seems to be caused by things such as phone disconnection during gameplay). Also, Unity Remote 4 does actually support touch controls properly from the script, not just a translator for PC controls (meaning it does actually register Touch Phases).

Spent ages trying to get the pinging feature to work like the animation used in my previous Ping post. Then I realised I had a left over OnMouseDown() this.Ping; code from the computer controls.

Then it still wasn't working, and it was because I was running all of my tap code after checking c.OverlapPoint(d2d.TouchPos(0)) , which basically meant that I was checking for the event where the user would lift their finger (that's the ending touch phase) but only when the finger was down and overlapping position. See the problem? I am amazing coder. Also on a side note:
    Debug.Log(Input.touches.Length + " | " + Input.GetTouch(0).phase);
catch { }

Don't try/catch everything without catching the error kids! Or evil Nanny Lovelace will scold you dearly.

After that I tried to get adding and removing the pointers working. The adding was easy due to how I've implemented adding pointers to be super smooth. The removing bit was, eh, rough. And I spent ages on it. And I mean ages, probably 3 or 4 hours. Then it turned out the problem was caused because of another silly. Specifically:

PROBLEM: Tapping on the centre node removes all of the pointers (specifically when lifting the finger off the screen while it was last over the node).

REASON: When a pointer detects that the finger is close to the centre (the node) when it is removed from the screen meaning the user wants to remove a node, then it sets its drag script to false then removes itself.

SOLUTION: This removal applies to ALL pointers since every pointer was checking to end the drag script. Even the ones that aren't dragging. Even if that means all of them. This was fixed by only checking for the drag release condition if the pointer was being dragged anyway. And since just tapping on the centre node doesn't start a pointer drag event straight away this fixed everything!

No comments:

Post a Comment