- Home /
Detecting points touched in sequence.
Using Rect(), I created 4 points as follows. (The co-ordinates are fake for now, cause my exacts co-ordinates are too long). The points are place in a diamond shape.
var p1 = Rect(x1,y1,10,10);
var p2 = Rect(x2,y2,10,10);
var p3 = Rect(x3,y3,10,10);
var p4 = Rect(x4,y4,10,10);
This is how it will appear.
[p1]
[p2] [p3]
[p4]
The player can use their fingers to move through the points to draw symbols. For start, I allow the users to draw Lightning, ^ and inverted ^. So lets say if player touches in the following sequence : (p1,p2,p3,p4). It draws a lightning shape. The player can also draw (p1,p3,p2,p4) to draw a reflected lightning shape. For the ^, the sequence is (p2,p1,p3) or (p3,p1,p2). For the last one, (p2,p4,p3) or (p3,p4,p2).
I tried using booleans but it ended up causing some booleans to be triggered unintentionally. I heard from my friend something about getting them into arrays but I got stuck at how to detect the sequence in the array.
Anyone can help?
Commenting about: Could you make empty game objects along the path that you want drawn, have the player draw, and if they have a certain success rate in the given game objects, it'll come up true true true false true, and thats 4/5 or 80 percent, above 75 percent, so you pass, so then it just counts up booleans that way, and then it could work that way... Does this make sense? If not, reply, I'll explain it further...
I think I can catch a little of it. But not sure how to count up the booleans.
Answer by Justin Warner · Dec 14, 2010 at 04:19 AM
Okay, Here it is explained a little more.
So, you want the player to draw a line...
X X X X X X X X X X
Above are 10 points... In order to pass, you need atleast 70 percent correct, so in other words, 7 of them must be right.
To do this, get the distance between what the user draws, and the actual game object (Represented by an X above)... Now, in the if statement to check if the distance is close enough, you can incrememnt a variable (Let's say, gotRight)...
So, when user is done drawing, whether it be pushing a button, or some other means, it checks between how many were possible (You can use http://unity3d.com/support/documentation/ScriptReference/GameObject.FindGameObjectsWithTag.html)
Now, that'll say how long, just use .length, and then divide the gotRight by the variable above, and that'll give you a percent. Now check whether or not that percent is >= .7, if so, then they got it right, if not, then they got it wrong...
Is that better?
It is still a little confusing. I don't really want to put too many gameobjects on the scene as what I have now is not the compiled version from my friend. I'm afraid it might cause lag issues in it.
I'm almost positive an empty game object takes no time at all as it is what it is... Empty, and it doesn't have to render or anything, you're using it as a place holder...
But wouldnt everything be triggered lets say if the user just randomly swipe through and touches all the points?
another thing to take note is that if i have to use that method, i will have to attach them all to my camera as the player will be moving in manner similar to Cave Run and other similar games.
That wouldn't be a problem (The camera part)...
Then, to counter messure, you could put "duds" in the scene, where you get more than 90 percent of them, then you fail... You can use the same script you'd use above, and just change the var names....
Your answer
![](https://koobas.hobune.stream/wayback/20220613090944im_/https://answers.unity.com/themes/thub/images/avi.jpg)