跟踪旋转量,然后根据逆时针或顺时针旋转减去或添加刻度

时间:2016-04-10 15:33:26

标签: c# unity3d rotation

我想跟踪一个轮子被旋转多少并将其应用到从-1到1的刻度。

例如。他/她顺时针旋转了2次。比例将增加0.5。他/她逆时针旋转3次,减少0.75。

到目前为止,我有车轮旋转(我使用触摸设备)

void Update () 
{
    changeTurnAmount (); 
    int nbTouches = Input.touchCount;
    if(nbTouches > 0)
    {
        for (int i = 0; i < nbTouches; i++)
        {
            Touch touch = Input.GetTouch(i);
            TouchPhase phase = touch.phase;
            switch(phase)
            {
            case TouchPhase.Began:
                //TODO
                break;
            case TouchPhase.Moved:
                // Here the wheel is moved
                wheel.transform.Rotate (0, 0, -(touch.deltaPosition.x), Space.World);
                break;
            case TouchPhase.Stationary:
                //TODO
                break;
            case TouchPhase.Ended:
                //TODO
                break;
            case TouchPhase.Canceled:
                //TODO
                break;
            }
        }
    }
}

我试图在这里尝试如何存储angleChange(理想情况是正面或负面,因此它可能是520,然后如果向左旋转则下降到300)。

public GameObject wheel;
public float rotationRate;
public float turnAmount;
public float angleChange;
private float previousAngle;
private float currentAngle;
private float newAngle;

void Start() {
    currentAngle = wheel.transform.rotation.z;
}

private void changeTurnAmount()
{
    previousAngle = currentAngle;
    currentAngle = wheel.transform.rotation.z;

    angleChange = previousAngle - currentAngle;

    turnAmount += angleChange;

    print (turnAmount);
}

但是,转弯量通常等于0.4。控制台日志的示例是&#39; 0.495072&#39;

提前感谢任何建议或代码段!

0 个答案:

没有答案