Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by karthees · Aug 05, 2014 at 11:49 AM · movement3dvuforia

3D model is not moving with finger

I'm doing vuforia app with unity. I'm displaying 3D model on the camera overlay, when i apply the transform to 3d model it won't get any action with my finger.

  using UnityEngine;
     using System;
     
     public class DynamicModelsGUI : MonoBehaviour
     {    
         private GameObject metaioMan;
         public GUIStyle buttonTextStyle;
         float SizeFactor;
         
         // variables for ray tracing
         private RaycastHit hit;
         private LayerMask layerMask = 1<<4;
     
         private bool selected = false;
         private Vector3 offset = new Vector3(0.0f, 0.0f, 0.0f);
         
         void Start() 
         {
             SizeFactor = GUIUtilities.SizeFactor;
             
             // Find metaioman object
             metaioMan = GameObject.Find("plan");
         }
         
         // Update is called once per frame
         void Update()
         {    
             SizeFactor = GUIUtilities.SizeFactor;
         
             // only handle touchs or clicks when metaioman is active, i.e.
             // is visible on tracking pattern
             if (metaioMan.active)
             {
                 if (Input.touchCount > 0)
                     // if tracking, then evaluate touch point
                     handleTouches();
                 else if (Input.GetMouseButton(0))
                     handleClicks();
                 else
                     selected = false;
             }
         }
         
         private void handleTouches()
         {
             // if there's touch points and the phase is began-->try to select the geometry
             if(Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
                 selectGameObject(Input.GetTouch(0).position);
             
             // if the touch point is moving and metaio man is selected
             if(Input.GetTouch(0).phase == TouchPhase.Moved && selected)
                 moveGameObject(Input.GetTouch(0).position);
             else if(Input.GetTouch(0).phase == TouchPhase.Ended)
                 // deselect metaio man if touch has ended
                 selected = false;
         }
         
         public void handleClicks()
         {
             // if there's left mouse click-->try to select the geometry
             if (!selected && Input.GetMouseButtonDown(0))
                 selectGameObject(Input.mousePosition);
             
             if (selected && Input.GetMouseButton(0))
                 moveGameObject(Input.mousePosition);
         }
         
         public void selectGameObject(Vector2 position)
         {
             // get a ray from the touch point
             Ray ray = Camera.main.ScreenPointToRay(position);
                 
             // layer mask, metaio man is on layer 4
             layerMask = 1<<4;
                 
             // cast a ray on layer 4, if metaio man has been hit
             if (Physics.Raycast(ray, out hit, 5000, layerMask) && hit.collider.gameObject.name == "plan")
             {
                 // metaio man is touched --> select it
                 selected = true;
                     
                 // swith to layer 8, find the initial touch point on the plane and use it as a reference
                 layerMask = 1<<8;
                 if (Physics.Raycast(ray, out hit, 5000, layerMask))
                 {
                     // record the offset of the touch point and the object position point
                     offset = hit.point - metaioMan.transform.position;
                 }
             }
             else
                 // not hit, don't select
                 selected = false;
         }
         
         public void moveGameObject(Vector2 position)
         {
             // cast a ray on layer 8 (the plane) to calculate the hit position of the plane
             Ray ray = Camera.main.ScreenPointToRay(position);
             layerMask = 1<<8;
             if(Physics.Raycast(ray, out hit, 5000, layerMask) && hit.collider.gameObject.name == "plan")
             {
                 // move the metaio man to the intersect of the ray and the plane, offset should be accounted for
                 metaioMan.transform.position = hit.point - offset;
             }
         }
         
         public void OnGUI()
         {
             if(GUIUtilities.ButtonWithText(new Rect(
                 Screen.width - 200*SizeFactor,
                 0,
                 200*SizeFactor,
                 100*SizeFactor),"Back",null,buttonTextStyle) ||    Input.GetKeyDown(KeyCode.Escape)) {
                 PlayerPrefs.SetInt("backFromARScene", 1);
                 Application.LoadLevel("MainMenu");
             }        
         }
     }



alt text

alt text

screen shot 2014-07-31 at 3.34.29 pm.png (9.5 kB)
screen shot 2014-07-31 at 3.34.36 pm.png (16.8 kB)
Comment
Add comment · Show 5
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
avatar image HarshadK · Aug 05, 2014 at 11:56 AM 0
Share

Did you check all the options that were provided to you for your previous question regarding the same issue: How to drag the 3D model in screen with finger?

avatar image karthees · Aug 05, 2014 at 12:05 PM 0
Share

I didn't add $$anonymous$$esh to here. I can't apply mesh to my 3D model

avatar image HarshadK · Aug 05, 2014 at 12:06 PM 0
Share

What type of collider are you using for your 3D model?

avatar image karthees · Aug 05, 2014 at 12:07 PM 0
Share

$$anonymous$$esh collider. see the images in updated code. I can't apply mesh to H$$anonymous$$I_$$anonymous$$irra_3D. I can apply only HAR$$anonymous$$Pads, HArms, Hback etc. Why?

avatar image HarshadK · Aug 05, 2014 at 12:25 PM 0
Share

Since you are using RayCast you need to have colliders for them to detect a hit with a collider.

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

21 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

Related Questions

Move Towards Mouse (Constant Movement)? 1 Answer

A node in a childnode? 1 Answer

Rotating doesn't work correctly? 2 Answers

Does Unity Work With DAZ? 2 Answers

Xcode initiate / call Unity game engine 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