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 DeSynCCC · Sep 24, 2016 at 09:24 AM · c#transformcollidersgameobjects

GameObject not changing position in PlayMode although the Transform changes

I have a problem and searched a whole day for a solution but can't seem to find one.
My problem is that I am trying to move a GameObject with the code provided at the bottom (But I am almost 100% sure that the code is NOT the problem).
But when I try to test it and hit Play in the Editor and then try to move a GameObject per mousedrag it does not move the GameObject.
Then I looked into the Editor and saw that only the BoxCollider has moved and the GameObject still is in the same place as before which is confusing to me because the Transform of the GameObject also moved to place where I dragged it...
I also have an other GameObject with a MeshCollider and when I try to drag and drop it around with the mouse in PlayMode it works...


Scripts:

 using UnityEngine;
 using System.Collections;
 
 public class LevelEditorTouchInputControl : MonoBehaviour {
 
     public LevelEditorManager levelEditorManager;
 
     // Use this for initialization
     void Start () {
     
     }
     // TODO test at home with android and convert to touchControl instead of MouseButtons
     void Update () {
         
         if (Input.GetMouseButtonDown(0))
             levelEditorManager.snapObject();
 
         if (Input.GetMouseButton (0))
             levelEditorManager.dragObject ();
 
         if (Input.GetMouseButtonUp (0))
             levelEditorManager.releaseObject ();
     }
 }


 using UnityEngine;
 using System.Collections;
 
 public class LevelEditorManager : MonoBehaviour {
 
     private float dist;
     private Transform toDrag;
     private bool dragging = false;
     private Vector3 offset;
 
     public void snapObject() {
 
         RaycastHit hit;
         Vector3 v3;
         Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
 
         if (Physics.Raycast(ray,out hit))
         {
             if (hit.collider.gameObject.transform.parent == null)
                 toDrag = hit.collider.gameObject.transform;
             else
                 toDrag = hit.collider.gameObject.transform.parent;
 
             Debug.Log ("ToDrag: " + toDrag.name);
             
             dist = hit.transform.position.z - Camera.main.transform.position.z;
             v3 = new Vector3(Input.mousePosition.x, Input.mousePosition.y, dist);
             v3 = Camera.main.ScreenToWorldPoint(v3);
             offset = toDrag.position - v3;
             dragging = true;
         }
     }
 
     public void dragObject() {
 
         Vector3 v3;
 
         if (dragging) {
             
             v3 = new Vector3 (Input.mousePosition.x, Input.mousePosition.y, dist);
             v3 = Camera.main.ScreenToWorldPoint (v3);
             toDrag.position = v3 + offset;
         }
     }
 
     public void releaseObject() {
 
         dragging = false;
     }
 }
 

The working one:
Before I drag it:
http://imgur.com/me9a91h
After I dragged it:
http://imgur.com/C8ktVLV

The not working one:
Before I drag it:
http://imgur.com/GTM8nCF
After I dragged it:
http://imgur.com/gSVFgb4
The editor view:
http://imgur.com/HQqEarS

Here you clearly see that I am somehow just dragging the BoxCollider which is weird because the Transform of the parent GameObject changes which then should move every child like the working one does above and not just the BoxCollider. Any ideas which lead to a possible solution are very much appreciated.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by ScaniX · Sep 24, 2016 at 09:25 AM

The second one is marked static, so you cannot move it.

Comment
Add comment · Show 1 · Share
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 DeSynCCC · Sep 24, 2016 at 11:35 AM 0
Share

Thank you, this fixed the problem!

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

240 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Need help getting randomly moving particles to head to the nearest of 4 coordinates. 1 Answer

How to make enemies go through colliders? 0 Answers

Infinite Time inbetween if statements? 2 Answers

Make object move back and forth 2 Answers

Vector3.Lerp not working properly, making the player bounce around 2 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