• 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 Raresh · Oct 31, 2016 at 02:07 PM · c#lookat

Children with LookAt in Update moves root object?

I have children that point to a raycasted distance from the root parent object. It makes the whole object drift a little (when it shouldn't). When I comment the LookAt function in Update it stops this weird behaviour. I tried using FixedJoint on the parent of the objects with LookAt (the parent of them is not the root though) but it only makes my object spin like crazy.

The objects with LookAt are attached at runtime through script, and have only a Mesh Collider.

Added a recording: https://www.dropbox.com/s/2wp1omxaasfwjc9/Unity%203D%2010.31.2016%20-%2021.12.21.01.mp4?dl=0

Sometimes you don't even have to rotate the object in order for it to trigger this behaviour, and a few times it even stops after a few seconds after you rotate it.

Added a .unitypackage to replicate: https://www.dropbox.com/s/26f5gzt647707oh/Test.unitypackage?dl=0 Just drag the prefab in the scene, set the rigidbody & target to the script in Root and the target to the Looks at target objects

Comment
Add comment · Show 11
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 TreyH · Oct 31, 2016 at 02:26 PM 0
Share

link your code / hierarchy?

avatar image Raresh TreyH · Oct 31, 2016 at 03:48 PM 0
Share

https://www.dropbox.com/s/26f5gzt647707oh/Test.unitypackage?dl=0

Basically it's what i said, rotate the object on an axis a bit and see it move by itself. Just from the children with LookAt relative to the parent's up. Once you disable the LookAt script, the object should stop moving by itself.

avatar image Raresh Raresh · Oct 31, 2016 at 04:13 PM 1
Share

alt text

This is the Hierarchy structure just so you get the idea. Root is where you attach AbsoluteTarget to, and a simple Look At script to look at Target, which is moved by the script in the Root to the hitpoint of the raycast.

For 2-3 Gameobjects with LooksAtTarget, the Root doesn't continue to move more than a few seconds. However, after 3 it doesn't stop moving, and very rarely it's even exponential.

untitled.png (4.7 kB)
Show more comments
avatar image Anton-Korhonen · Oct 31, 2016 at 06:03 PM 0
Share

Where's your LookAt script? The script you attached definitely moves only the target gameobject.

avatar image Raresh Anton-Korhonen · Oct 31, 2016 at 06:12 PM 0
Share

It literally takes less time to make it than to copy it. Just download the file above or just write

 public GameObject target;
 
 void LateUpdate()
 {
             transform.LookAt(target, transform.parent.up);
 }


avatar image Anton-Korhonen Raresh · Oct 31, 2016 at 07:04 PM 0
Share

So if i got this correctly: You have a Root gameobject with AbsoluteTarget and LookAt scripts attached. Some of the children of Root also have the LookAt script attached to them. All of the LookAt script targets are set to the same target gameobject that AbsoluteTarget Target transform is.

With this setting the Root gameobject shouldn't move. The LookAt script won't do anything when attached to Root (as there is no transform.parent).

I tested this in a project and the child gameobjects are looking at the Target without any jumping or twiggling. Do you have a rigidbody attached to your Root gameobject? $$anonymous$$aybe the problem is somewhere else?

Show more comments

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.

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

233 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer

LookAt() is looking at (0,0,0) when given a child object 0 Answers

Initialising List array for use in a custom Editor 1 Answer


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