• 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 Josh 4 · Sep 03, 2010 at 07:04 PM · transformdoorrotatearound

transform.RotateAround problems

I'm trying to rotate a door gameObject using the transform.RotateAround method and I'm getting some weird behavior. Now, before anyone asks, I'm doing it t$$anonymous$$s way instead of using an animation for a reason, so please don't tell me to use an animation instead. Instead of behaving as a door should, the door comes off of the point where its $$anonymous$$nge should be and rotates further off into the distance with each mouse click. Here's a snippet:

  • $$anonymous$$nge is the Vector3 to rotate around
  • AngleToOpen is the angle I want to rotate the object to

    transform.RotateAround(t$$anonymous$$s.$$anonymous$$nge, Vector3.up, -t$$anonymous$$s.AngleToOpen);

    Thanks for any help that anyone may be able to give.

    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
    1

    Answer by swhite · Sep 03, 2010 at 08:27 PM

    Try rotating a smaller object around the $$anonymous$$nge (t$$anonymous$$nk of it as the door $$anonymous$$nge part) then c$$anonymous$$ld your door to t$$anonymous$$s smaller object so that it moves in rotation with the $$anonymous$$nge.

    Example:

    Image Link : alt text (quick and cheesy door example picture ;) ) Basically here's what you 'could' do.

    You have your door frame a $$anonymous$$nge on the frame, a $$anonymous$$nge on the door and the door.

    You then rotate the $$anonymous$$nge on the door around the $$anonymous$$nge on the door frame.

    transform.RotateAround ($$anonymous$$nge.transform.position, Vector3.up, 20 * Time.deltaTime);

    Then you add any constraints that you want (IE don't rotate past t$$anonymous$$s point, stop on collision, whatever you want)

    Comment
    Add comment · Show 1 · 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 NPSF3000 · Sep 26, 2010 at 08:41 AM 0
    Share

    You could make a "Empty" gameObject to do this.

    avatar image
    0

    Answer by bubbalovesponge · Nov 13, 2013 at 07:53 PM

     /////////////////////////////////////////////////////////////////////////////////
     //
     //    T$$anonymous$$sOpenDoor.cs
     //    Created:        Darren Hedlund microcyb@gmail.com
     //
     //    description:    Script to open a door when the Player is near
     //
     //                  Note: To change the pivot point use t$$anonymous$$s URL by VoxelBoy.
     //                  http://solvethesystem.wordpress.com/2010/01/15/solving-the-pivot-problem-in-unity/
     //                    or create a seperate Empty GameObject and attach door mesh to it
     /////////////////////////////////////////////////////////////////////////////////
     
     using UnityEngine;
     using System.Collections;
     
     public class T$$anonymous$$sOpenDoor : MonoBehaviour
         {
         float smooth = 2.0f;
         float DoorOpenAngle=90.0f;
         float DoorCloseAngle=0.0f;
         Quaternion target;
         private Transform _target;
     
         void Start()
             {
             DoorCloseAngle=t$$anonymous$$s.transform.localEulerAngles.y;
             if(DoorCloseAngle<=0)
                 {
                 DoorOpenAngle=90.0f;
                 }
             else
                 {
                 DoorOpenAngle=t$$anonymous$$s.transform.localEulerAngles.y-90.0f;
                 }
             }
     
         void Update()
             {
             GameObject _target = GameObject.FindGameObjectWithTag("Player");
             if (_target != null)
                 {
                     float dist = Vector3.Distance(_target.transform.position, t$$anonymous$$s.transform.position);
                     if (dist < 8.00f)
                         {
                         target= Quaternion.Euler (0, DoorOpenAngle, 0);
                         t$$anonymous$$s.transform.localRotation = Quaternion.Slerp(t$$anonymous$$s.transform.localRotation, target, Time.deltaTime     * smooth);
                         }
                     if (dist > 8.00f)
                         {
                         target= Quaternion.Euler (0, DoorCloseAngle, 0);
                         t$$anonymous$$s.transform.localRotation = Quaternion.Slerp(t$$anonymous$$s.transform.localRotation, target, Time.deltaTime * smooth);
                         }
                 }
             }
         }
    
    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

    1 Person is following this question.

    avatar image

    Related Questions

    Android game lags when using transform.RotateAround to rotate an object with many children 2 Answers

    Animating sliding door, rotation problem 2 Answers

    transform.rotate only 1 time for 180 degrees? 1 Answer

    how to rotate game-Object in a fixed position 1 Answer

    Door rotating the wrong way around. 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