Search Unity

Place Object Depending on Swipe Direction

Discussion in 'Scripting' started by Vetlecn, Sep 2, 2021.

  1. Vetlecn

    Vetlecn

    Joined:
    Jul 11, 2021
    Posts:
    6
    Hi!

    I am working on a mobile game and got stuck on one of the features. I am trying to place out blocks of a fixed size with an angle depending on what direction the user swipes from their registered touch. Anyone who knows how to do this? Tried to make some pictures to explain my problem better.

    Thank You!
    upload_2021-9-2_22-31-59.png
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,695
    You an use
    Mathf.Atan2()
    to get the angle (in radians) of a given line (eg, startpoint -> endpoint line segment).

    Multiply the output by
    Mathf.Rad2Deg
    and you have degrees you can rotate your block by.
     
    Vetlecn likes this.