Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Doft · May 11, 2012 at 01:07 AM · transformrotatechild

Rotating a transform using it's child

I have a character that is made of a container GameObject named "Player", and it's child are the body, arms, legs, etc. I want it to turn and shoot at the direction the player clicks with the mouse, but I want it to turn using it's right arm as reference, not the whole Transform. This is how I'm doing it:

// 240, 160 is the center of the screen, the player is always centered
var look : Vector3 = Vector3(mouse.position.x - 240, thisTransform.position.y, touchHandler.position.y - 160);
thisTransform.forward = look.normalized;
This is a script in the "Player" GameObject. If I try to use the right arm transform (rightArmTransform.forward = look.normalized), only the right arm would turn, not the whole body. How can I make the whole body rotate using the right arm?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by stingman · May 11, 2012 at 06:13 AM

Access the parent of that object or the root of that object (depending on what's being parented to the arm:

transform.parent / transform.root. Adjust the transform of the parent accordingly. this should help you out:

http://unity3d.com/support/documentation/ScriptReference/Transform-parent http://unity3d.com/support/documentation/ScriptReference/Transform-root.html

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 Doft · May 13, 2012 at 07:39 PM

That's not really what I'm asking. Here's a screen to ilustrate what I want: alt text

When you click on the screen, the player rotates so that the shot that comes from the arm will move in that direction. I'm having some trouble to find how much I should rotate. With the code above that I'm using, since the player's center is the capsule's center, the shot is a little offset. But if I rotate the right arm, it's also incorrect since it would only rotate the arm, not the parent. In the picture, if I click along the red lines the body would rotate 0/90/180/270 degrees, no matter where along the line I click.


unity.png (26.9 kB)
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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

movement to certain child object 0 Answers

Error getting the transform of a child object. 1 Answer

2D platformer firing left and right, help! 1 Answer

Moving multiple objects(same objects) in different directions 1 Answer

Separate child rotation 1 Answer


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