0 votes

Greetings,

I'm really stuck on this. How would you go about detecting shapes (like triangles or squares) as touch input?

I tried using arypbatista/godot-swipe-detector from the asset lib. But i really don't know what i'm doing or even where to start.

any advice will be greatly appreciated. Thanks in advance for your time!

in Engine by (12 points)

1 Answer

+1 vote
   if start_point.distance_to( touch_point ) > 50:  # min distance
        if start_point.angle_to( touch_point ) > rad2deg( 30 ) and < rad2deg( 90 ):
              # this is example how detect line with angle i.e. triangle

if you need fixed shapes (triangle):

triangle = 0

   if start_point.distance_to( touch_point ) > 100 and < 200:
       var angle = start_point.angle_to( touch_point )
       if triangle == 0:  # stage of triangle
           if angle  > rad2deg( 30 ) and angle < rad2deg( 70 ):
                triangle = 1
                start_point = touch_point    # this is basic mechanics
       elif triangle == 1:
           # next angle

hard to explain all variants, but, you need aprox this code.
and upgrade:
start_point = touch_point ---- in best case need: touch_points = [] and touch_points.append(touch_point)
if touchpoints.back().distanceto( touch_point ) > 100:
then you need line between last 2 poins (create vector) and if angle between this vector and current touch point > 30deg. (determination error), then touch_points.append(touch_point)
Finale, when user unpress touch, need just ...

if touch_points.size() == 3: # triangle
    for i in touch_points:
       #check angles
by (76 points)

Thank you so much for answering.
I will give this a try when I get home!

Or another variant:
Collect all points if if touch_points.back().distanceto( touch_point ) > 50 (precision), and add to array.
then analize array points if points["angle"].max < ~30 (max angle bitween each) - it seems to be circle...
if have 3 angles = ~60 - triangle
if 4 angles > 80 and < 100 - square
or if you need pentagram.... you need have 5 angles ~36 deg each.

P.S. and check angle direction... if you have 2 angles clockwise and 2 conter and start and end point in some place - this is not square... )
and remember - check distance bitween start and and point (in some case not i.e. line or "Z"))

small addon: you can make check lotal length of vectors for come reason...
if shape need some size, or use for more powerfull magick cast - small triangle - typical fireball - big - more powerfull...

variant for curves (circle):
find in array min/max x and y point - you get square - find center, check distance bitween each point and center if min and max distance ~ equal - this is circle....
in "infinity" - need intersection in center....

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.