• 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 omarmoh · Jul 01, 2015 at 08:56 PM · parentlocalposition

Follow the the parent normally but without y and z axis ?

So here is my setup i have a parent and a child i want the child to follow the parent but not to follow the parent local z and y axis.

So lets say that the parent is at 0,0,0 and the child of that parent is at 0,0,1 and i started the game and lets say suddenly the parent moved forward, in this case the child well move forward too and stay at 0,0,1 and that is not what i want i want the parent to move forward and backwards and up and down without effecting the child but if the parent moves left and right i want the child to follow left and right also.

Would really love an answer for this problem and would like to know if there is a way without parenting.

btw i'm sorry if the question is to long i just wanted to be specific for everyone to understand.

Comment
Add comment · Show 3
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 meat5000 ♦ · Jul 01, 2015 at 09:03 PM 1
Share

What have you tried?

avatar image omarmoh · Jul 01, 2015 at 09:10 PM 0
Share

I can't think about any thing to get what i want :(

avatar image omarmoh · Jul 15, 2015 at 11:31 AM 0
Share

Sorry if i am talking too much and not getting what i want to be clear.

Here is some photos of what i want.

as you can see the object follows the highlighted object every time it rotates and moves on it's own x axis but it doesn't follow it when it moves forward as in photo 3 this is what i want to achieve.

Photo Photo 2 Photo 4 Photo 3 Photo 5

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Myth · Jul 01, 2015 at 10:16 PM

in basic psudo code, with no parenting

var for followed object

update loop

transform.position = new vector 3 (other object.transform.pos.x , 0, 0);

done. - you could also go as far as to put a rigidbody on the following object and constrain movement on the y and z axis, but remember about the gravity and i'm not sure that would work with parenting.

Comment
Add comment · Show 7 · 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 omarmoh · Jul 01, 2015 at 10:20 PM 0
Share

This will make me follow the object in the world x axis i want to follow the object in his local x axis.

avatar image Myth · Jul 03, 2015 at 12:05 AM 0
Share

so use transform.localposition ? am I missing something big here? perhaps give a little more context re what and why

avatar image omarmoh · Jul 03, 2015 at 09:25 AM 0
Share

look i have a child and a parent and if i use transform.localposition.x = 0 that will do what i want but the problem is that if the parent moves in his local forward z axis the child will also follow him and i don't want that.

avatar image Myth · Jul 12, 2015 at 09:49 AM 1
Share

is it necessary to parent?

avatar image GiyomuGames · Jul 12, 2015 at 10:11 AM 1
Share

$$anonymous$$yth is correct. Don't make your object a child of the object you want to follow on the x axis. It will make it easy to accomplish what you are trying to do using $$anonymous$$yth code above. Note that you can calculate the variation of your "parent"'s x if you want to follow its movement but not necessarily be at the exact same x.

Show more comments

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

23 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

Related Questions

Lerp a Child but 'keep up locally' with Parent 0 Answers

Help with firing projectiles out of turret 1 Answer

Is there a way to lock the local position of a game object? 0 Answers

Scale gameobject around vector 0 Answers

Local Position 0,0,0 on Instantiate without Parent 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