c#unity flpping y轴在旋转播放器上下颠倒

时间:2017-09-08 21:19:10

标签: c# unity3d rotation flip

好的,所以这已成为一个星期的问题,现在我似乎无法弄明白我试图在y轴上翻转我的潜艇一旦颠倒。它在我的鼠标位置旋转我会告诉你我的代码。

//This code rotates my submarine on mouse position which is perfect.

    Vector3 RayPos = cam.WorldToScreenPoint(transform.position);
    Vector3 dir = Input.mousePosition - RayPos;
    float angle = Mathf.Atan2(dir.y, dir.x) * Mathf.Rad2Deg;
    Quaternion rotation = Quaternion.AngleAxis(angle, Vector3.forward);
    transform.rotation = Quaternion.Slerp(transform.rotation, rotation, 
    rotateSpeed * Time.deltaTime);


//now this code is my problem once my sub goes upside down it flips (y) but 
  it only does it once but then when i go back the correct way it wont flip 
  on (y) anymore.

    Debug.Log(Mathf.Abs(Vector3.Dot(transform.up, Vector3.up)));
    if (Mathf.Abs(Vector3.Dot(transform.up, Vector3.down)) < 0.125f)
    {
        if (Mathf.Abs(Vector3.Dot(transform.right, Vector3.down)) > 0.825f)
        {
            SubTrans.localScale = new Vector3(transform.localScale.x, -1, 
            transform.localScale.z);
        }
        else
        {
            SubTrans.localScale = new Vector3(transform.localScale.x, 1, 
            transform.localScale.z);
        }
    }

0 个答案:

没有答案