- Home /
Draw a circle on touchscreen
Hey everyone,
I once played this nice little game on a smartphone. The player had to draw a circle with his finger on the touchscreen. The circle was drawn visible on the screen and then the player was given feedback on how accurate the circle was.
So I would like to know how to best approach something like that.
Getting Input from the finger and drawing a symbole
Checking the accuracy of the drawing and giving feedback.
I'm not looking directly for code (but always welcome;) but rather a pointer in the right direction.
Thank you.
Do we know the center of circle around which user is going to draw a circle?
Answer by awest · Oct 20, 2014 at 02:00 PM
I start tackling that problem by taking vector points every so often from when the touch starts to when the touch ends. You could use Camera.ScreenPointToRay and LineRenderer. Those can give you a connect the dots effect (with or without dots). When the touch ends you can auto complete by accessing the first vector point.
If you want to fill in the circle perhaps you can generate a mesh/2D shape, but I have little experience in that.
To check accuracy, get the center of the drawn circle. Take the radius using each vector point. The closer to average radius each one is means the more perfect the circle is.
I'm sure there is an advanced formula that takes each point and the preceding point and figures out where the next one should be based on the difference between them and the diameter of the circle and something else, but that may be overkill.
Hey Thanks for your answer. Good Idea. Would you go and say something like get the position of the touch every so often (frame/time) to create the connect the dots effect?
At the moment I'm tryong out to get the correct touch.position. I thought I could use the touch.position to start the line renderer at the correct position but somehow the world space and the touch.position are not working correct together (my instatiated object is always to far off).
Yeah, maybe log the touch every second or two. $$anonymous$$ake it an easily adjustable variable so you can test and tweak.
Touch inputs register on in 2D pixel space so it has to be converted to a unity world space. There are a few good methods to do that and many tutorials on Unity answers. I prefer using the ScreenPointToRay method of whichever camera you are using.
Your answer
Follow this Question
Related Questions
draw and compare 1 Answer
Smooth draw curve line 0 Answers
gui draw rexture problem 1 Answer
Procedural Mesh 1 Answer