playMaker

Author Topic: vector2 0-1 to degrees?[SOLVED]  (Read 1536 times)

peaks

  • Playmaker Newbie
  • *
  • Posts: 27
vector2 0-1 to degrees?[SOLVED]
« on: December 07, 2017, 05:16:17 AM »
Hey everyone!
I'm developing my first daydream app, but I'm stuck with some math-conversion problem:
I would like to rotate a gameobject with the daydream-controller touchpad (depending on the fingerposition on the touchpad). When I put my finger on the touchpad it detects my exact finger-position and stores it into a vector2 variable from 0-1 on both x & y axis. How can I covert the individual values from 0-1 and vice versa into one single degree-float ranging from 0 to 360°?

I made a quick visualisation to give you guys a better idea:
« Last Edit: December 09, 2017, 01:10:33 PM by peaks »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: vector2 0-1 to degrees?
« Reply #1 on: December 07, 2017, 12:52:34 PM »
Hi.
Maybe you can get the angle from the center of the touchpad to to finger position instead of using the axis and convert.

peaks

  • Playmaker Newbie
  • *
  • Posts: 27
Re: vector2 0-1 to degrees?
« Reply #2 on: December 09, 2017, 01:09:14 PM »
Hi! Thanks for the reply. I've got a working script which I would like to share. Maybe someone wants to recreate it for playmaker or has the same problem.
The result is a public float (xtestAngle) which you can use in playmaker again :)
Code: [Select]
public class RadialTouch : MonoBehaviour {

    public float xtestAngle;
    void Start () {

    }

    void Update()
    {
        Vector2 xtest = GvrControllerInput.TouchPosCentered;

        xtestAngle = getAngle(xtest);
        print(xtestAngle);
    }

     public float getAngle(Vector2 point)
    {
        float angle = Mathf.Atan2(point.x, point.y) * Mathf.Rad2Deg;
        return angle + (angle < 0 ? 360f : 0f);
    }
}