|
I'm able to get the Line Renderer working now. Just want to share with others for those who may be facing the same problem that I had. Managed to get it done thanks to Herman. Here's my code:
(comments are locked)
|
|
The magic function you are looking for is ScreenToWorldPoint. It is a method of Camera. So to use it, put a reference to a Camera in the script where you want to make the call - a public field, like this:
Then construct a new Vector3. The first two coordinates are the xy coordinates that you get from touch. The third coordinate is the distance from your camera. So
Now you have a point in 3D space that you can use to construct the curve. As in the GUILabel solution, it is easiest to keep track of these points in an array. (Especially if you want to interpolate or simplify the curve). The last thing is then to synch up your LineRenderer positions with those in the array. The slow solution is to update the positions in every Update, like this:
Get this working first, then it should be easy to update the line renderer positions only as needed, and filter points (you do not need to add each and every touch point to this curve). I am actually working on a something with similar functionality, and am experiencing some lag with the line renderer method as well (although in my case, there might be other issues), so it might be some work to get it nice and responsive. i keep getting the error of the lineRenderer not able to read the position from my array.
Nov 02 '10 at 07:41 AM
Robindoo
do i call the screenPoint and worldPoint in the update function?
Nov 03 '10 at 02:31 AM
Robindoo
Yup, see the modified code.
Nov 03 '10 at 06:21 AM
Herman Tulleken
Thanks once again. It really works. Now i have a better understanding over LineRenderer. Just need to tweak it so it wont fade off so fast.
Nov 04 '10 at 03:13 AM
Robindoo
No prob. BTW, if you come across a lag issue, I would be very interested in a solution (check out my question here: http://answers.unity3d.com/questions/26037/how-do-i-prevent-deal-with-input-lag-on-a-touch-interface).
Nov 04 '10 at 05:48 AM
Herman Tulleken
(comments are locked)
|

You have to call lineRenderer.SetVertexCount to have the right number of nodes (the same number as in your array).
(Call it before any call to SetPosition).
you really don't need to change the question title to "solved" in answers - just accepting the answer is good enough! ;)