Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 unity_Wd9us_rR3t_Emg · Oct 01, 2019 at 07:48 AM · movementmobileselecting objects

Mobile select and move Object with offset

Hey! I am working on a mobile project and trying to move objects by double clicking on them and then dragging them, while selected and moving the object is supposed to have a little offset on the y-axis to make it clear which object is handled. So far Clickslection and Doubleclick event is working, the movement is also working and the offset but only the first time I select an object it gets the offset. When I select and move it again it just moves around but doesn't get the y-axis offset. The chosen Objects are Rigidbodies & Colliders, so they fall back on their own. But I can't find why the Y-Offset is only applied once per Object-Lifetime.

 if (Input.GetTouch(0).phase == TouchPhase.Ended && _doubleClickActivated == true)    
         {
             _selectedObject.transform.GetChild(0).gameObject.GetComponent<Rigidbody>().isKinematic = false;      
             _selectedObject.transform.GetChild(0).gameObject.GetComponent<Rigidbody>().detectCollisions = true;
 
             _selectedObject.layer = 0; 
 
             if(_selectedObject.transform.childCount > 0)
             {
                 _selectedObject.transform.GetChild(0).gameObject.layer = 0;    
             }
 
             if(_selectedObject.transform.GetChild(0).childCount > 0)
             {
                 _selectedObject.transform.GetChild(0).GetChild(0).gameObject.layer = 0;
             }
 
             _selectedObject = null;     
             _objSelected = 0;   
             _objectFix = true;             
             _doubleClickActivated = false;   
         }
 
         if (_objectFix == false)   
         {
             if(_objSelected == 1)   
             {
                 RaycastHit hit;
                 Ray ray = _cam.ScreenPointToRay (touch.position);   
                 if (Physics.Raycast(ray, out hit))          
                 {
                     _selectedObject.transform.GetChild(0).gameObject.GetComponent<Rigidbody>().isKinematic = true;      
                     _selectedObject.transform.GetChild(0).gameObject.GetComponent<Rigidbody>().detectCollisions = false;
                     
                     _selectedObject.transform.position = new Vector3(hit.point.x, hit.point.y+0.2f, hit.point.z);       
                 }
             }
 
         }

Is the code I came up with for moving the object. Since the Doubletap & Object Detection seems to work fine I assume the mistake lies within that part. All the selection code does is raycast on the finge position, move the hit object to the Raycast ignore layer and save a reference to the selected object.

If anyone could find out what the problem with the offset only applying once that would be awesome :)

EDIT: Oh forgot to mentiont that the code is part of the update function, in case that is relevant.

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

213 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 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

Selecting objects and limiting movement space 0 Answers

Movement Object 0 Answers

How do I stop an object from cloning when moving? 1 Answer

Rigid Body Movement (Mobile Issue) 3 Answers

My character has stopped moving 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