2

I have been working on Augmented Reality Kudan's unity SDK. I have seen the tutorials in which the objects seems to be static but when I tried the objects kept on rotating which do not meet my requirements and I am unable to stop the rotation. If you help in stopping the rotation then I shall remain thankful to you!

user3599561
  • 103
  • 1
  • 1
  • 6

2 Answers2

0

Do you mean that the object rotates relative to your own phone rotation? I ran in to this problem, wanting to place a 2D plane perpendicular to the camera in Kudan with markerless tracking. Depending on my own rotation, it would keep the plane in the same world orientation, so that at different rotations it would not be perpendicular. I solved it by hard coding an orientation translation when the Augment object is activated with the MarkerlessTransformDriver.

0

I think you should use markerless augmented reality for this and it doesn't require any sdk for that just a lines of code

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class WebCamScript : MonoBehaviour {

    public GameObject WebcamPlane;
    public Button FireButton;
    // Use this for initialization
    void Start () {
        if(Application.isMobilePlatform)
        {
            GameObject cameraParent = new GameObject("camParent");
            cameraParent.transform.position = this.transform.position;
            this.transform.parent = cameraParent.transform;
            cameraParent.transform.Rotate(Vector3.right, 90);
        }

        Input.gyro.enabled = true;

        WebCamTexture webCameraTexture = new WebCamTexture();
        WebcamPlane.GetComponent<MeshRenderer>().material.mainTexture = webCameraTexture;
        webCameraTexture.Play();

        FireButton.onClick.AddListener(OnButtonDown);

    }

    void OnButtonDown()
    {
        GameObject bullet = Instantiate(Resources.Load("bullet", typeof(GameObject))) as GameObject;
        Rigidbody rb = bullet.GetComponent<Rigidbody>();
        bullet.transform.rotation = Camera.main.transform.rotation;
        bullet.transform.position = Camera.main.transform.position;
        rb.AddForce(Camera.main.transform.forward * 500f);
        Destroy(bullet, 3);

        GetComponent<AudioSource>().Play();
    }

    // Update is called once per frame
    void Update ()
    {
        Quaternion cameraRotation = new Quaternion(Input.gyro.attitude.x, Input.gyro.attitude.y, -Input.gyro.attitude.z, -Input.gyro.attitude.w);
        this.transform.localRotation = cameraRotation;

    }
}
Nima
  • 3,309
  • 6
  • 27
  • 44
Maaz Irfan
  • 81
  • 8