- Home /
Swipe Patterns to unlock efects
Imagine a door that only opens if you swipe a circle into the left direction, or a square to the left.
Any ideas how to do this. I'm working on something liike this:
Imagine this... i draw a circle on swipe, but i want an efect after this. The way I'm thinking of doing it is to Instantiate a wall with cubes and as i move the swipe or mouse it touches cubes and destroys them, like this:
You can see the cubes here just for example purposes but they will be invisible after, the cubes will be instantiated on touch or mouseclick. Then after the swipe ends depending on what cubes were destroyed it triggers an efect... like opening a door casting a spell etc.
What you guys think? Is this a good aproach? Can someone tell me if there is a better way to do this. I'm also think of doing squares, triangles and other figures.
Note: I dont have money to buy assets and if this turns out any good i'll share it for free on asset store since i couldn't find anything similar to this for free.
Answer by noio · Jul 29, 2014 at 04:39 PM
The cube thing is clever, and from what I'm reading it is similar to the way some gesture recognition works.
I would suggest a more analytical approach, looking at the motion data directly, since the cubes will only give you yet another list of coordinates to process and detect the shape of.
Keep a list of cursor coordinates between mouseDown and mouseUp, (or touch). Then detect what kind of shape these points form.
For a circle, quoting from a post on Kirupa by Sirisian:
Take the average position of all the points and call this the center. Find the average distance to the center from each point. (point - center).Length() for each point then divide by the number of points. Call this the radius. Then find the error of each point. (point - center).Length() - radius. That value should be less than a percentage of the radius. The next step is to find out if the points are in a clockwise or counter clockwise ordering.
For squares and triangles, things get a little more tricky. You might have to detect straight line segments using something like a Hough Transform (demo), and then see what shape these lines form.
Alternative: If you really don't need the shapes to have different rotation/size, you can do something similar to your block approach, where you mark which tiles belong to the "triangle" and give success if a minimum percentage of those is destroyed. This is actually mentioned in the same topic.
Thank you for the help. I can't upvote because I don't have 15 reputation yet.
Your answer
![](https://koobas.hobune.stream/wayback/20220613155312im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Objectives based on object appear. 2 Answers
object move in three lanes 1 Answer
Android 2D game how to create swipe left/right views 2 Answers
Connection between 2 scripts 1 Answer
Multiple Cars not working 1 Answer