Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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 thunts7 · Jan 23, 2015 at 07:08 AM · child

Can a child be stationary while a parent object moves?

I am using some scripts i downloaded off of the asset store for npc navigation. the scripts are easiest to use if they have a gameobject as a target to move to. id like to use this to make wandering animal npcs so i want an object assotiated with the parent animal but i want that object to stay stationary with comparison to the world and have the animal move towards this object and reach it then ill make a script to pick a new location. I would basically like to know if a child can be stationary and still allow the parent to move freely.

Comment
Add comment · Show 1
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 fafase · Jan 23, 2015 at 07:09 AM 0
Share

You would have to apply the invert movement and rotation to the child object.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by GameVortex · Jan 23, 2015 at 07:40 AM

So you want the target gameobject to be a child of the moving animal gameobject ? That is going to complicate a lot of things for you. As a general rule, whenever you want a child gameobject to be stationary while the parent moves around it is almost always no point in having the child gameobject be parented to the moving object at all.

I recommend you to instead put both the animal and the target gameobject into another parent gameobject, that way you have them both organized and you do not have to apply some complicated movement code to the target to make it stationary.

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 thunts7 · Jan 23, 2015 at 06:50 PM 0
Share

thanks having both the animal and the target as children worked perfectly. it leaves the empty game object that is the parent of the two in the same place but that shouldn't be a problem.

avatar image
1

Answer by Rayeloy · Feb 07, 2020 at 04:19 AM

While Its not usually recommended to do this (because it makes basically no sense in the majority of situations), it is indeed possible to not move a child with its parent, here is the code for the script I did. Just drag and drop it on the GameObject that you don't want to move with its parent:

     using System.Collections;
     using System.Collections.Generic;
     using UnityEngine;
     
     
     [ExecuteAlways]
     public class DontMoveWithParent : MonoBehaviour
     {
         Vector3 savedPosition;
     
         [Tooltip("When DontMoveWithParent is on, Ctrl+Z doesn't work for movement changes on this GameObject.")]
         public bool dontMoveWithParent = true;
         bool lastDontMoveWithParent = true;
     
         Vector3 parentLastPos;
     
         private void Update()
         {
             if (transform.hasChanged && !transform.parent.hasChanged && savedPosition != transform.position)
             {
                 savedPosition = transform.position;
                 transform.hasChanged = false;
             }
     
             if (!lastDontMoveWithParent && dontMoveWithParent)
                 savedPosition = transform.position;
     
                 lastDontMoveWithParent = dontMoveWithParent;
         }
     
         private void LateUpdate()
         {
             if (dontMoveWithParent)
             {
                 if (savedPosition == Vector3.zero)
                 {
                     savedPosition = transform.position;
                 }
     
                 if (transform.parent.hasChanged)
                 {
                     transform.position = savedPosition;
                     transform.parent.hasChanged = false;
                 }
             }
         }
     }
 

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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Make a simple tree 1 Answer

OnCollisionEnter(Collision Other) setActive affecting parent 1 Answer

Making child rotation/position independent of that of parents' 1 Answer

Using same named childs for Prefab 2 Answers

Problem with Parent and Child using LookAt 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