0

I made a script to move the camera on a terrain containing montains on mobile device.

I am trying to make a movement script for Android to move the camera over a terrain like it is done on Google maps.

public LayerMask terrainMask;

// This mask need to be not used elsewhere
// Needed for raycasting
public int layerAlone;
GameObject[] previousTouchPointAndInputMask;

    void Start()
    {
        previousTouchPointAndInputMask = new GameObject[3];
        for (int i = 0; i < 3; i++)
        {
            previousTouchPointAndInputMask[i] = new GameObject("PlatformController Input platform");
            previousTouchPointAndInputMask[i].AddComponent<BoxCollider>().size = new Vector3(float.MaxValue, 1, float.MaxValue);
            previousTouchPointAndInputMask[i].layer = layerAlone;
        }
    }

void LateUpdate()
{
        Ray ray;
        UnityEngine.RaycastHit hitInfo;

        if (Input.GetButtonDown("Fire1") && Input.touchCount == 1)
        {
            // Construct a ray from the current mouse coordinates
            ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            Physics.Raycast(ray, out hitInfo, float.MaxValue, terrainMask);

            previousTouchPointAndInputMask[0].transform.position = hitInfo.point;
            previousTouchPointAndInputMask[0].transform.localRotation = Quaternion.identity;
        }
        else if (Input.GetButton("Fire1") && Input.touchCount == 1)
        {
            // Construct a ray from the current mouse coordinates
            ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hitInfo, float.MaxValue, 1 << layerAlone))
            {
                Vector3 movement = previousTouchPointAndInputMask[0].transform.position - hitInfo.point;
                movement.y = 0;
                transform.Translate(movement);
            }
        }
  }

This script is attach to the camera.

So i am working with ray cast.

To avoid montains to block raycasting, after the initial raycast on terrain, next raycast are done on an invisible horizontal plane.

This script is working to move horizontally on any terrain.

Now I am trying to make similar things with two fingers (to apply rotation and zoom in zoom out) but I can't find a solution.

I tried to apply one ray cast per fingers, then i don't know what to do with the data.

Any idea ?

Similar question

Community
  • 1
  • 1
Orion
  • 301
  • 3
  • 12
  • "Any idea?" is a terrible question to ask. Please elaborate on what exactly you are trying to do and what you need to know, I have not the slightest idea what it is you are trying to accomplish here or what the problem might be. – CodeSmile Jan 23 '15 at 10:19
  • "Now I am trying to make similar things with two fingers (to apply rotation and scale)". Shoul I say it in another way? Anyway, I tried to explain it more precisely. I hope to be clear enough. – Orion Jan 24 '15 at 16:33

0 Answers0