我如何向四元数添加灵敏度? C#

问题描述 投票:-1回答:1

我有一个带有敏感度变量的脚本,但是无法弄清楚我在代码中的位置。任何专家都可以在这里帮助我吗?

我要添加此:

public float sensitivity = 5.0f;

进入四元数旋转的代码:

switch (firstTouch.phase)
{
    case TouchPhase.Began:
        firstpoint = firstTouch.position;
        xAngTemp = xAngle;
        yAngTemp = yAngle;
        break;

    case TouchPhase.Moved:
        secondpoint = firstTouch.position;
        //Mainly, about rotate camera. For example, for Screen.width rotate on 180 degree
        xAngle = xAngTemp  + (secondpoint.x - firstpoint.x) * 180.0f / Screen.width;
        yAngle = yAngTemp  - (secondpoint.y - firstpoint.y) * 90.0f / Screen.height;
        //Rotate camera
        this.transform.rotation = Quaternion.Euler(yAngle, xAngle, 0.0f);
        character.transform.rotation = Quaternion.Euler(yAngle, xAngle, 0.0f);
        break;
}
c# unity3d vector quaternions
1个回答
0
投票

可能不是专家,但简单地将其相乘怎么办

xAngle = xAngTemp  + (secondpoint.x - firstpoint.x) * 180f  * sensitivity / Screen.width;
yAngle = yAngTemp  - (secondpoint.y - firstpoint.y) * 90f * sensitiviy / Screen.height;

尽管我建议宁愿使用Vector2以便能够对x和y使用单独的灵敏度

public Vector2 sensitivtiy = Vector2.one * 5f;

...

xAngle = xAngTemp  + (secondpoint.x - firstpoint.x) * 180f  * sensitivity.x / Screen.width;
yAngle = yAngTemp  - (secondpoint.y - firstpoint.y) * 90f * sensitiviy.y / Screen.height;
© www.soinside.com 2019 - 2024. All rights reserved.