• 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 /
  • Help Room /
This question was closed Aug 31, 2015 at 11:09 PM by Grogzz for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Grogzz · Aug 30, 2015 at 04:32 PM · transform.rotate

Rotation problem

Hi everyone,

I'm currently making a game where the player controls a tank. In the hierarchy the object Tank is the parent containing all the other parts, Base / Turret / Tracks are all children of Tank and Barrel is the child of Turret.

I'd like to be able to move the Barrel up and down to aim and to do so I tried to rotate it along the x axis.

Because a picture is worth a thousand words :

Problem with rotation

The left tank with a nice barrel and the right tank with a weird looking barrel. I tried to move the Barrel out of the Tank and the rotation behaves normally.

Here's my question, is there a way to make the rotation without changing the actual shape of the Barrel ? Is there something wrong with my hierarchy ?

Thank you for your attention.

SOLVED : The parent scale has to be 1/1/1 if you plan to rotate any of its children. Otherwise you'll get a different shape while rotating.

Thank you @Scribe.

rotation-problem.png (388.4 kB)
Comment
Add comment · Show 8
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 ForeignGod · Aug 30, 2015 at 04:47 PM 0
Share

I'm not sure if i understood your problem correctly, but is it so that your barrel rotates from its center? If that's the case you need to change where it pivots, using either a new empty gameobject or change it through something like blender.

avatar image Grogzz · Aug 30, 2015 at 05:35 PM 0
Share

I forgot to mention that the barrel is made with Blender. I moved the origin to the right so the rotation acts the way I want.

The problem is that while I rotate the barrel it's shape changes, it gets shorter and thicker. I just want to move it up and down like a barrel would do.

If something is still unclear don't hesitate to ask me for more information :)

avatar image ForeignGod · Aug 31, 2015 at 02:10 PM 0
Share

Could you post your code for rotating the barrel?

avatar image Grogzz · Aug 31, 2015 at 03:10 PM 0
Share

I also thought I was doing it wrong but I have the same result with the editor rotation tool.

The code looks like :

 using UnityEngine;
 using System.Collections;
 
 
 public class Tank : $$anonymous$$onoBehaviour {
     
     private GameObject barrel;
     private float rotationSpeed = 5.0f;
     private Vector3 rotation = new Vector3(rotationSpeed, 0.0f, 0.0f);
     
     void Start() {
         barrel = GameObject.Find("Barrel").gameObject;
     }
     
     void FixedUpdate() {
         barrel.transform.Rotate(rotation * Time.deltaTime);
     }
 }

I made a new tank with the same hierarchy and now it works fine but I'm still curious to know what happened with this one.

avatar image Scribe · Aug 31, 2015 at 03:25 PM 2
Share

Somewhere in the heirarchy, it has a parent with non (1, 1, 1) scale, so it is affected by its parents scale after the rotation is applied. That's my guess!

Show more comments

0 Replies

  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Bouncing Ball Problem( bounces vertically forever) 0 Answers

transform.Rotate is returning unexpected results 1 Answer

Stop player turning when facing object? 0 Answers

Duplicate, Translate and Rotate Quad so that edges meet 0 Answers

return all models to original location (image target) 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