【问题标题】:Unity object rotation speed differs on deviceUnity对象旋转速度在设备上有所不同
【发布时间】:2014-11-04 08:07:24
【问题描述】:

我有一个对象,当用户将手指拖过它时我会向左或向右旋转,而在 iPad4 上这非常流畅。

但是,在 iPhone 6 Plus 或 Nexus 4 上,在响应拖动到有时几乎不旋转的地步时会有非常明显的延迟?

这就是我的更新方法...我做错了什么以确保旋转感觉和外观在不同设备上都相同吗?

void Update () {

    // test for touch 
    if (Input.touchCount == 1) {

        // grab reference to this touch
        Touch userTouch = Input.GetTouch(0);

        // ray from cameara to point of finger touch
        Ray ray = Camera.main.ScreenPointToRay( Input.GetTouch(0).position );

        // hit object to record details of what was hit (touched)
        RaycastHit hit;

        // if the hit was on the Collider object
        if ( Physics.Raycast(ray, out hit) && hit.collider.gameObject.name == "MyObject") {

            // process the relavent phase...
            if (userTouch.phase == TouchPhase.Began) {
            }
            else if (userTouch.phase == TouchPhase.Moved) {

                // user is moving finger so rotate model
                transform.Rotate(0.0f, -userTouch.deltaPosition.x * _rotationSpeed, 0, Space.Self); 
            }
            else if (userTouch.phase == TouchPhase.Ended || userTouch.phase == TouchPhase.Canceled) {
            }
        }
    }
}

【问题讨论】:

    标签: unity3d rotation touch transform


    【解决方案1】:
    -userTouch.deltaPosition.x * _rotationSpeed * time.deltaTime
    

    time.deltaTime

    time.deltaTime 将确保没有帧速率的依赖,因为“deltaTime”指的是从最后一帧过去了多少时间。在 Update 方法的计算中添加 always time.deltaTime 很常见,尤其是那些涉及移动或计时的计算

    【讨论】:

    • 或者您可以在 FixedUpdate 方法中更新旋转/位置。但大多数情况下使用 deltaTime 是可行的方法。
    • 感谢大家的帮助 ;-) 感谢 ;-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-20
    • 1970-01-01
    • 2015-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多