• 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 sigtau · Jan 24, 2012 at 05:39 AM · rotationparentchild

Smooth rotation change of a parent object without affecting child

Okay, I'm completely stumped as to how to tackle this one. I'm in the process of coding a third person game, and I'm having trouble figuring out some basic camera/movement controls.

Here's my setup: I have a character with an empty 'pivot' game object in the center of teh character's mesh. The pivot has MouseLook attached, and the main camera is a child object of the pivot--this, effectively, allows the player to move the mouse and rotate the camera around the character freely.

I have another object on the other side of the pivot, equidistant from the pivot (just like the camera). This is used for the Head Look Controller, so that the character looks where the camera is facing.

In the interest of making movement more natural (so that the character's feet do not slide on the ground when rotation occurs), I would like it so that when the character is stationary, the camera can rotate around him freely, but when a button to move is pressed the character re-orients himself so that he is facing where the camera was looking--or more specifically, the rotation value of the pivot. Preferably, I'd like this to occur via a lerp of some kind, so that the rotation is smooth and not abrupt.

This presents two problems:

  1. Infinite lerping. If you're constantly lerping to match the rotation of the child object, you're going to infinitely spin in a circle, since child rotation is affected by parent rotation.

  2. Camera offsetting--If I choose to cache the rotation of the child object, then when the character orients to match this rotation, the camera is still offset and not in-line with where the character is facing. When the character is moving, the camera should stay behind the character (NO Y-axis rotation on the pivot) at all times.

  3. Possibly using quaternions. If I have to use quaternions to solve this problem, I'd like it to be the least painful method possible, because I absolutely cannot understand quaternions in Unity for the life of me.

Does anyone have any ideas on how to tackle this problem?

Comment
Add comment · Show 7
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 syclamoth · Jan 24, 2012 at 05:43 AM 0
Share

Well, everything you can do here will ultimately use Quaternions, and you don't really need to understand how they work for them to be useful.

I'm not quite clear on one point here- what is the order of the transform hierarchy here? Could you tell us what objects are children of what? I usually don't make the camara-controller a child of anything- this allows it to move freely without being influenced by the rotation of the player (for camera-relative movement). Is there any real reason why the camera must be a transform child of the charater?

avatar image sigtau · Jan 24, 2012 at 11:48 AM 0
Share

The hierarchy is as follows, from rootmost to innermost:

Character -> Camera Pivot -> Camera/Head Look Target.

avatar image syclamoth · Jan 24, 2012 at 11:53 AM 0
Share

Well then, refer the answer to a similar question that's been floating around today. You don't need the camera pivot to be the child of the Chararacter- in fact, I would say that it would cause more problems than it's worth. Just have the camera pivot copy the character transform's location (with an offset, if nessecary), and then work from there down.

avatar image sigtau · Jan 24, 2012 at 12:14 PM 0
Share

transform.position only grabs world space coordinate values, and does not consider rotation values, am I correct in saying that?

avatar image syclamoth · Jan 24, 2012 at 12:16 PM 0
Share

Yes. That's kind of the point.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by sigtau · Jan 24, 2012 at 11:31 PM

Managed to solve this myself via guidance from syclamoth in the comments. Detached the camera pivot, attached a script to it that locked its transform to the coordinates of the character, and now, all is well.

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

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Make a simple tree 1 Answer

Changing child's rotation changes parent's position 0 Answers

Parent object to face childs rotation... 1 Answer

Where to find original unity Parent/Child script? 2 Answers

Parent-independent rotation 2 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