• 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 garanon · Dec 12, 2011 at 06:57 AM · parentdragfollow

Follow Script

When I am dragging one object, I want another object in the scene to move as well. At the moment I have pretty simple scripts attached. Here is the one on the object that drags:

 function Update(){
     StaticVarDisc.PosX = transform.position.x; //this is defining posx etc
     StaticVarDisc.PosY = transform.position.y;
     StaticVarDisc.PosZ = transform.position.z;
     if (drag){
         var ray: Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         var distance: float;
         if (plane.Raycast(ray, distance)){
             transform.position = ray.GetPoint(distance);
         }
     }
 }

and here is the code attached to the object I want to follow:

 function Update () {
     transform.position.x = StaticVar.PosX; //this is calling posx etc
     transform.position.y = StaticVar.PosY;
     transform.position.z = StaticVar.PosZ;
 }
 

This code works, but there is a slight delay for the other object to catch up (very small, but noticeable). If I drag the object fast enough, I can actually get them to overlap. I want them to appear more solid though as if they were a single object.

I understand there will always be delay, but could anyone suggest an alternative to make it update a bit faster to appear more solid and move as one object rather than two?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by bouke1 · Dec 12, 2011 at 11:17 AM

I think.its because tje follow script updates before te other script. and will have the old values of the position.

Try to put in the direct refference to the position

Comment
Add comment · 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
0

Answer by asafsitner · Dec 12, 2011 at 09:11 AM

Make the second object a child of the first. You might want to move it to the desired position first, though, as it will stay there until you unparent them.

Forgot to add that the object will move to relative space instead of world space so you'll have to be more careful when moving it independently in the future.

Use the transform.parent property to accomplish this.

Comment
Add comment · 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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

how to do full child-parent transformation, without parenting? 2 Answers

How to make a child game object move based on the parent position ? 2 Answers

Following another object's position/rotation like parent/child relationship? 4 Answers

[SOLVED] Particle system follows root bone of actual parent bone. 3 Answers

Camera rotation around player while following. 6 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