Search Unity

How To Determine if two vectors are inline for collision.

Discussion in 'Scripting' started by renman3000, Sep 28, 2016.

  1. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    Hi there,
    I want to make a function which will handle multi touch: pinch zoom and rotate camera.

    I have determined that tbis is a tricky scenario. Both situations have (at times) positions which are approaching each other. The greatest difference is if they are approaching each other on the same line (will hit - pinch zoom in) or if they are approaching each other but will never hit each other as they are on opposite sides of the screen (rotate cam).

    So, if I have two delta vectors, and two corresponding positional vectors.... How do I determine if these two will (most likely) hit each other or not?

    Hmmmmm
    Calculating.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,697
    To determine pinch/zoom you need to measure the distance between two touching points (using Vector3.Distance() perhaps) and compare it this frame to a previous frame distance value.

    If it changes more than a threshold, you have started a pinch/zoom maneuver.

    To determine two-finger rotation, you need to get the angle of the line between the two points (using Mathf.Atan2() perhaps) and compare it this frame to a previous frame angle value.

    If that changes more than a threshold amount, you have started a rotation maneuver.
     
    renman3000 likes this.