Unity获得滑动角度

时间:2014-11-07 06:06:53

标签: android unity3d touch

我处理两个CONTACT A,按下并释放屏幕,我如何获得旋转角度?像这场精彩的比赛一样控球。

void Start () {
    guiText.text = "Touch the screen.";
    AddForce ();
}

// Update is called once per frame
void Update () {
    touch = Input.GetTouch (0);
    TouchPhase phase = touch.phase;
    switch(phase)
    {
    case TouchPhase.Began:
        guiText.text =("New touch detected at position " + touch.position);
        a_pos = touch.position;
        break;
    case TouchPhase.Ended:
        guiText.text =("Has cansel by " + touch.position);
        b_pos = touch.position;
        Calculate();
        AddForce ();
        break;      

        }
    }

Instruction

Wonderful game

1 个答案:

答案 0 :(得分:1)

您可以在滑动结束时从滑动开始创建矢量:

 Vector2 swipe = b_pos - a_pos;

如果要查找该矢量和水平轴之间的角度,可以计算:

float angle = Vector2.Angle(Vector.right, swipe);

但是如果您要使用AddForce的角度,则可以将a_posb_pos从屏幕坐标转换为世界坐标,并使用这些点为{{{{{{ 1}}:

AddForce