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
2
Question by paco morales · Jan 11, 2011 at 06:05 PM · rotationrotateaxischildrenorientation

How to fix the rotation and Orientation in an object as a Children ?

Hello,

I'm working in this Robot-Toy, I am trying to fix the rotation of the arm, but the Arm rotates keeping the same orientation don't change (always see to the same direction).

(The Base's Arm (in color green) rotates well, but the Arm as a "children" rotates keeping the same orientation)

Please take a look to the image.

alt text alt text

Here it is the Script I am using for the base in green color.

var gunSpeedNeg: int = -40; var gunSpeedPos: int = 40; function Update () {

 if(Input.GetKey("r")){
 transform.Rotate(Vector3.right* gunSpeedNeg* Time.deltaTime);

                     }
 if(Input.GetKey("y")){
 transform.Rotate(Vector3.right* gunSpeedPos* Time.deltaTime);
                     }

 }

And here it is the script for the arm " who has to rotate according to the arm but it doesn't (It rotates but always keeping the same orientation)

var gunSpeed : float = 40;

private var rotation : Quaternion = Quaternion.identity; private var left : Quaternion = Quaternion.AngleAxis(-150, Vector3.up); private var right : Quaternion = Quaternion.AngleAxis(30, Vector3.up);

function Start () { // This piece of code will allow you to remember the origin. rotation = transform.rotation; left = rotation left; right = rotation right; }

function Update () { var speed = gunSpeed * Time.deltaTime;

 if(Input.GetKey("a"))
 {
     rotation = Quaternion.RotateTowards(rotation, left, speed);
 }

 if(Input.GetKey("d"))
 {
     rotation = Quaternion.RotateTowards(rotation, right, speed);
 }

 transform.rotation = rotation;

}

Any advice is welcome.

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 Paulius-Liekis · Jan 11, 2011 at 06:21 PM 0
Share

Could you rephrase your question? It's very unclear which parts you want to rotate and which you want to keep static. Because basically if you parent some thing and then rotate parent, then children will rotate with parent.

avatar image Statement · Jan 11, 2011 at 07:24 PM 0
Share

Love the pictures.

1 Reply

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

Answer by Statement · Jan 11, 2011 at 06:20 PM

Your code should rotate the whole hierarchy. It sounds to me that your children have some code affecting their world rotation somehow. Are there other scripts involved?

  1. Make sure your hierarchy is nested, not flat. You might have written code that set position to some joint manually, which would explain the behavior.
  2. Check all other scripts that can influence the rotation or position of the child parts to isolate the issue.


In your updated code you set rotation this way:

transform.rotation = rotation;

This sets the world rotation (absolute rotation) of the object. You likely want to set the local rotation, so hierarchy rotations are preserved. This is done simply.

transform.localRotation = rotation;

Likewise, you should store the localRotation in your Start function.

rotation = transform.localRotation;
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 paco morales · Jan 11, 2011 at 06:45 PM 0
Share

Hi Statement,

Yes you help me to make the scripts for the arm, not for the base. here you can see the scripts, but let me rephrase my question for Paulius Liekis.

Please take a look to my thread

http://forum.unity3d.com/threads/73454-I-can%92t-make-the-Arm-Base-rotate-in-Axis-quot-Y-quot?p=470412#post470412

avatar image Statement · Jan 11, 2011 at 07:23 PM 0
Share

I have updated my answer. Basically you are overwriting the world rotation every frame. You should set the local rotation ins$$anonymous$$d.

avatar image paco morales · Jan 11, 2011 at 08:23 PM 1
Share

Thanks $$anonymous$$an it works !!! I owe you a bottle of Tequila :)

avatar image Statement · Jan 11, 2011 at 08:47 PM 0
Share

Where can I collect it? :D

avatar image paco morales · Jan 13, 2011 at 09:18 PM 0
Share

You can collect it here in $$anonymous$$exico or I can pay you the cost of it, But I don't know about prices in Sweden I think is a little expensive than $$anonymous$$exico :)

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.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

how to know if an axis has been full rotated? 1 Answer

How can i rotate the aircraft elevator around the yellow axis up and down ?? as shown in the pic 0 Answers

Rotating an object on Z axis while moving 1 Answer

Moving an object based on the position of another object 2 Answers

Need help with rotation script. 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