玩家跟随手指拖动,但慢慢地

时间:2015-02-17 06:10:41

标签: unity3d

我正在使用正交相机并在触摸时移动播放器。 transform.x是左/右运动和 transform.z是左上/下移动

我的代码工作正常,但速度很慢,因为它没有准确地跟随拖动的手指。

这是我的代码:

if (Input.touchCount > 0) {
        foreach (Touch touch in Input.touches) {
            RaycastHit hit;
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast (ray, out hit, 100)) {
                if (touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved) {
                    var cameraTransform = Camera.main.transform.InverseTransformPoint (0, 0, 0);
                    player.transform.position = Camera.main.ScreenToWorldPoint (new Vector3 (touch.position.x , touch.position.y, cameraTransform.z - 0.5f));
                }

                // when touch finish, stop the player where it is last time.
                if(touch.phase == TouchPhase.Ended){
                    player.rigidbody.velocity = Vector3.zero;
                }
            }
        }

    }

我需要一个解决方案。提前谢谢。

0 个答案:

没有答案