Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Kraidworm · May 22, 2019 at 12:43 PM · rotation2d game

How to rotate parent only without affecting children?

I have child objects which I want to the freeze their rotation, but be affected by the parents movement.

How do I go about this?

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by pmerilainen · May 22, 2019 at 03:01 PM

I think the easiest way is not to use hierarchy at all. Just use a script in each of the follower that keeps their distances at fixed offset from a transform (player in this case).

Comment
Add comment · Show 2 · 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 Kraidworm · May 22, 2019 at 03:13 PM 0
Share

How would one go about this?

avatar image Kraidworm · May 29, 2019 at 01:28 PM 0
Share

Thanks a lot, I got it working as I wanted.

avatar image
0

Answer by hederson_3_12 · May 22, 2019 at 01:26 PM

In the same function, you rotate the parent you should have the reference to his child's and rotate them the same amount as the father but in negative but why you need to do that?

Comment
Add comment · Show 3 · 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 Kraidworm · May 22, 2019 at 01:57 PM 0
Share

I have four child objects of my player. These objects are targets for the camera, when the player is in certain states I want the camera to move to one of these objects. I want these children to maintain their position, move with the player, but not rotate. Hope this helps.

Here are my rotate functions, how should I proceed?

 void RotateLeft()
     {
         transform.Rotate(Vector3.forward * rotatespeed);
 
         z += Time.unscaledDeltaTime * -rotatespeed;
 
 
     }
 
     void RotateRight()
     {
 
         transform.Rotate(Vector3.back * rotatespeed);
 
         z += Time.unscaledDeltaTime * -rotatespeed;
         
     }

avatar image MJRobUnity Kraidworm · May 22, 2019 at 02:21 PM 0
Share

If I understand what the guy above has said, you could adapt these to take a transform being passed in. then where you call them pass in the player transform. then immediately after that have a foreach that will do the children in the opposite direction

so:

 RotateLeft(this.transform);
 foreach (Transform t in this.transform)
 {
 RotateRight(t);
 }

I think that is how you get the transform children. I have not tested this. You could also give them a kinematic rigid body and lock rotation. That might work. Or their own script which constantly sets the rotation to their start/specified rotation.

avatar image Kraidworm MJRobUnity · May 22, 2019 at 02:49 PM 0
Share

I'm not the best at Unity so I'm struggling to understand what you suggested first. I've tried using the rigid body route you suggested earlier, but as fair I can tell it doesn't work. I haven't tried what you suggested last, but I'm not sure how I go about that.

avatar image
0

Answer by CruS · May 22, 2019 at 02:15 PM

Perhaps this will help?

https://docs.unity3d.com/2019.2/Documentation/Manual/class-RotationConstraint.html

"Freeze Rotation Axes"

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.

Follow this Question

Answers Answers and Comments

169 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

Related Questions

Flip the player with arm rotation 2 Answers

Setting rotation of player equal to rotation of a Line from Line Renderer,Get the rotation of Line Renderer and equal it to the rotation of the player 0 Answers

Rotate objects by mouse 2 Answers

problem with rotation 2D 1 Answer

,Rotating a 2D sprite with Input 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