Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Joy0023 · Jan 20, 2018 at 02:43 PM · rotationtouchscalechangeinteraction

Rotate and Size a GameObject in ARCore

Hello everybody I've this problem, using ARCore example scene I'm trying to rotate and Scale the AndyGameObj using my touch. Using the PlayerPrefInt "Status" 0 or 1 trying to divide the "game" in 2 parts, first you put the gameobj in the scene and than you interact with him. I can't figure put why I can't interact whit Andy o.o

this is my script:

public void Update() {

         if (PlayerPrefs.GetInt("Status") == 0)
         {
             if (Input.GetKey(KeyCode.Escape))
             {
                 Application.Quit();
             }

             _QuitOnConnectionErrors();


             // Check that motion tracking is tracking.
             if (Frame.TrackingState != TrackingState.Tracking)
             {
                 const int lostTrackingSleepTimeout = 15;
                 Screen.sleepTimeout = lostTrackingSleepTimeout;
                 return;
             }

             Screen.sleepTimeout = SleepTimeout.NeverSleep;

             Frame.GetPlanes(m_NewPlanes, TrackableQueryFilter.New);
             for (int i = 0; i < m_NewPlanes.Count; i++)
             {
             GameObject planeObject = Instantiate(TrackedPlanePrefab, Vector3.zero, Quaternion.identity,
                     transform);
                 planeObject.GetComponent<TrackedPlaneVisualizer>().Initialize(m_NewPlanes[i]);
             }

             // Disable the snackbar UI when no planes are valid.
             Frame.GetPlanes(m_AllPlanes);
             bool showSearchingUI = true;
             for (int i = 0; i < m_AllPlanes.Count; i++)
             {
                 if (m_AllPlanes[i].TrackingState == TrackingState.Tracking)
                 {
                     showSearchingUI = false;
                     break;
                 }
             }

             SearchingForPlaneUI.SetActive(showSearchingUI);

             // If the player has not touched the screen, we are done with this update.
             Touch touch;
             if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began)
             {
                 return;
             }
             // Raycast against the location the player touched to search for planes.
             TrackableHit hit;
             TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinBounds | TrackableHitFlags.PlaneWithinPolygon;

             if (Session.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit))
             {
                 var andyObject = Instantiate(AndyAndroidPrefab, hit.Pose.position, hit.Pose.rotation);

                 // Create an anchor to allow ARCore to track the hitpoint as understanding of the physical
                 // world evolves.
                 var anchor = hit.Trackable.CreateAnchor(hit.Pose);

                 // Andy should look at the camera but still be flush with the plane.
                 andyObject.transform.LookAt(FirstPersonCamera.transform);
                 andyObject.transform.rotation = Quaternion.Euler(0.0f, andyObject.transform.rotation.eulerAngles.y, andyObject.transform.rotation.z);

                 // Make Andy model a child of the anchor.
                 andyObject.transform.parent = anchor.transform;
                 Debug.Log("PIAZZATO");
             }
             PlayerPrefs.SetInt("Status", 1);

         }


         else if (PlayerPrefs.GetInt("Status") == 1)
         {
            GameObject objectInGame = GameObject.Find("Model");


             for (int i = 0; i < Input.touchCount; i++)
             {
                 if (i == 0)
                 {
                     Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;

objectInGame.transform.Rotate(Vector3.up -touchDeltaPosition.x Time.deltaTime * rotationSpeed); } else if (i == 1) {

                     Touch touch0 = Input.GetTouch(0);
                     Touch touch1 = Input.GetTouch(1);
                     if (touch0.phase == TouchPhase.Moved && touch1.phase == TouchPhase.Moved)
                     {
    Vector2 prevDist = (touch0.position - touch0.deltaPosition) - (touch1.position - touch1.deltaPosition);
                         Vector2 curDist = touch0.position - touch1.position;
                         float delta = curDist.magnitude - prevDist.magnitude;
                         defaultScaleX = objectInGame.transform.localScale.x;
                         defaultScaleY = objectInGame.transform.localScale.y;
                         defaultScaleZ = objectInGame.transform.localScale.z;

                         if (delta > 0)
                         {
                             //if (defaultScaleX >= currentScaleX * 4)
                             //{

                             //}
                             //else if (defaultScaleX < currentScaleX - 0.1)
                             //{

                             //}
                             //else 
                             // if (defaultScaleX < currentScaleX)


                             defaultScaleX = defaultScaleX + 2.5f;
                             defaultScaleY = defaultScaleY + 2.5f;
                             defaultScaleZ = defaultScaleZ + 2.5f;
              objectInGame.transform.localScale = new Vector3(defaultScaleX, defaultScaleY, defaultScaleZ);

                                                         
                         }
                         else if (delta < 0)
                         {

                             defaultScaleX = defaultScaleX - 2.5f;
                             defaultScaleY = defaultScaleY - 2.5f;
                             defaultScaleZ = defaultScaleZ - 2.5f;
              objectInGame.transform.localScale = new Vector3(defaultScaleX, defaultScaleY, defaultScaleZ);

                         }
                     }
                 }
             }
         }
     }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

174 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Change object scale by touch (in game) ^ 0 Answers

How do I use both touch and gyro to transform rotate the camera? 3 Answers

Player position relative to rotating platform [gif included] 0 Answers

Scaling animation that takes rotation into account 0 Answers

how to rotate fpsController in android device? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges