• 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 OmegaFalcon · Oct 21, 2020 at 11:56 PM · transform.positionfollowparent-child

How to have child object only follow parent x position

I have a background image that was a child to the camera so that it moves with the camera, but when the camera rotates, i don't want the background to rotate with it.


I thought the obvious solution was to just set the bg to the camera's x position in the update function, but for some reason, this resulted in a very choppy background movement. I also tried forcing the bg's rotation to stay at 0, but that doesn't affect it's world rotation so it still rotates with the parent. I tried making the bg turn in the opposite direction from the camera, but this was difficult to make look good.


Is there a way to to get bg to follow the camera's x-position smoothly?

Comment
Add comment · Show 2
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 makled · Oct 22, 2020 at 01:03 AM 0
Share

Hey @OmegaFalcon, have you tried using bg.transform.localEulerAngles(0f, 0f, 0f); ?

avatar image OmegaFalcon makled · Oct 22, 2020 at 09:34 PM 0
Share

yes i have. Doing that doesn't make a difference since it only affects the local rotation. When the parent rotates, the child's rotates with it but it's local rotation is still 0

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by SquashedGames-Studios · Oct 22, 2020 at 01:04 AM

I think setting the bg to the camera's x position will work if you the bg is not a child of camera, does it have to be a child?

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 OmegaFalcon · Oct 22, 2020 at 02:29 AM 0
Share

Doesn't have to be a child. When I was making it follow the camera's x transform, it wasn't a child of it then though so that doesn't work.

avatar image
0

Answer by NullOverrideX · Oct 22, 2020 at 09:51 AM

I'm not sure, but you can try

 transform.position = targetOb.position(x)

I don't have Unity near me and I'm only 9 years old so I'm not sure if this works. (My guess is probably not but this is the best I can do.

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 corapeca · Oct 23, 2020 at 03:10 AM

try freezing y and z movement,
make bg child of the camera, and add a rigidbody body to bg, then disable use gravity, then go to constraints, freeze all rotations and freeze movement of y and z.
I hope that might help.

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

142 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

Related Questions

Unity Object Aligment in Different Resolutions and Scales 0 Answers

One child object move differently as 0.0001f when moving parent 1 Answer

(C#) Follow target (script) transform target PREFAB 0 Answers

can i let the sphere follow a point(x.y. or.z) on plane? 1 Answer

Make an object do exactly what another, but later 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges