Beispiel #1
0
    void FixedUpdate()
    {
        Vector2 direction       = touchPad.GetDirection();
        Vector2 pointerPosition = touchPad.GetPointerPosition();

        if (touchPad.HasGotFirstTouch())
        {
            pointerPosition = Camera.main.ScreenToWorldPoint(pointerPosition);
        }
        else
        {
            pointerPosition.x = 0;
        }

        Vector3 movement = new Vector3(((pointerPosition.x) - (gameObject.transform.position.x)), direction.y, 0);

        GetComponent <Rigidbody>().velocity = (movement * speed);
        GetComponent <Rigidbody>().position = new Vector3
                                              (
            Mathf.Clamp(GetComponent <Rigidbody>().position.x, boundary.xMin, boundary.xMax),
            0.0f,
            Mathf.Clamp(GetComponent <Rigidbody>().position.z, boundary.zMin, boundary.zMax)
                                              );

        //robotMesh.transform.rotation = Quaternion.Euler(90f, GetComponent<Rigidbody>().velocity.x * (-tilt), GetComponent<Rigidbody>().velocity.x);
        robotMesh.transform.localRotation = Quaternion.Euler(0, GetComponent <Rigidbody>().velocity.x *(-tilt), 0);
    }