Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to change the position of my object in ar world #1

Open
sexypreneur opened this issue Oct 30, 2017 · 0 comments
Open

How to change the position of my object in ar world #1

sexypreneur opened this issue Oct 30, 2017 · 0 comments

Comments

@sexypreneur
Copy link

Please reply @HippoAR

Like the cat is moving in ARWorld

Move my gameObject up from existing position in AR world but none of it works.

I'm trying to do transform.DOMove(....) to move the gameObject up AR World. I also tried changing the localposition

But none of that works. Object ie. prefab stays at same position.

How do we move the object that's instantiated in AR World?

I have commented the code in which I'm also directly modifying the transform but doesn't work either.

DOTween is free Tweening package to Tween an Object

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.iOS;
using DG.Tweening;
using UnityEngine.UI;

public class TestHitControl : MonoBehaviour {

	public GameObject obj;
	private UnityARSessionNativeInterface m_session;

	// Use this for initialization
	void Start () {
		DOTween.Init(false, true, LogBehaviour.ErrorsOnly);
		m_session = UnityARSessionNativeInterface.GetARSessionNativeInterface ();
	}
	
	// Update is called once per frame
	void Update () {
		if (Input.touchCount > 0) {
			if (Input.GetTouch (0).phase == TouchPhase.Began) {
				createGameObject ();
			}
		}
	}

	void createGameObject(){
		Vector3 screenPos = Camera.main.ScreenToViewportPoint (Input.GetTouch (0).position);
		ARPoint point = new ARPoint{ x= screenPos.x,y=screenPos.y };

		ARHitTestResultType[] resultTypes = {
			ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent, 
			// if you want to use infinite planes use this:
			//ARHitTestResultType.ARHitTestResultTypeExistingPlane,
			ARHitTestResultType.ARHitTestResultTypeHorizontalPlane, 
			ARHitTestResultType.ARHitTestResultTypeFeaturePoint
		}; 

		foreach (ARHitTestResultType resultType in resultTypes)
		{
			List<ARHitTestResult> hitResults = m_session.HitTest (point, resultType);
			if (hitResults.Count > 0) {
				GameObject currentObj = GameObject.Instantiate (obj);
				
				currentObj.transform.position = UnityARMatrixOps.GetPosition (hitResults [0].worldTransform);
				currentObj.transform.rotation = UnityARMatrixOps.GetRotation (hitResults [0].worldTransform);
				currentObj.transform.LookAt (new Vector3(Camera.main.transform.position.x, currentObj.transform.position.y, Camera.main.transform.position.z));
				
				myText.text = currentObj.transform.position.ToString(); 

				StartCoroutine(SlideUp(currentObj)); 

				//new WaitForSeconds(10f);
				//obj.transform.DOMove(currentObj.transform.position + (Vector3.up * 100), 10); 
			}
		}
	}

	IEnumerator SlideUp(GameObject currentObj) {
		yield return new WaitForSeconds(1f);
		obj.transform.DOMove(currentObj.transform.position + (Vector3.up * 100), 10);
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant