Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 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 this 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 hinge should be and rotates further off into the distance with each mouse click. Here's a snippet:

  • hinge is the Vector3 to rotate around
  • AngleToOpen is the angle I want to rotate the object to

    transform.RotateAround(this.hinge, Vector3.up, -this.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 hinge (think of it as the door hinge part) then child your door to this smaller object so that it moves in rotation with the hinge.

    Example:

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

    You have your door frame a hinge on the frame, a hinge on the door and the door.

    You then rotate the hinge on the door around the hinge on the door frame.

    transform.RotateAround (hinge.transform.position, Vector3.up, 20 * Time.deltaTime);

    Then you add any constraints that you want (IE don't rotate past this 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

     /////////////////////////////////////////////////////////////////////////////////
     //
     //    ThisOpenDoor.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 this 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 ThisOpenDoor : MonoBehaviour
         {
         float smooth = 2.0f;
         float DoorOpenAngle=90.0f;
         float DoorCloseAngle=0.0f;
         Quaternion target;
         private Transform _target;
     
         void Start()
             {
             DoorCloseAngle=this.transform.localEulerAngles.y;
             if(DoorCloseAngle<=0)
                 {
                 DoorOpenAngle=90.0f;
                 }
             else
                 {
                 DoorOpenAngle=this.transform.localEulerAngles.y-90.0f;
                 }
             }
     
         void Update()
             {
             GameObject _target = GameObject.FindGameObjectWithTag("Player");
             if (_target != null)
                 {
                     float dist = Vector3.Distance(_target.transform.position, this.transform.position);
                     if (dist < 8.00f)
                         {
                         target= Quaternion.Euler (0, DoorOpenAngle, 0);
                         this.transform.localRotation = Quaternion.Slerp(this.transform.localRotation, target, Time.deltaTime     * smooth);
                         }
                     if (dist > 8.00f)
                         {
                         target= Quaternion.Euler (0, DoorCloseAngle, 0);
                         this.transform.localRotation = Quaternion.Slerp(this.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.

    Follow this Question

    Answers Answers and Comments

    1 Person is following this question.

    avatar image

    Related Questions

    Animating sliding door, rotation problem 2 Answers

    How to limit the angle of a camera with transform.RotateAround? 1 Answer

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

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

    Android game lags when using transform.RotateAround to rotate an object with many children 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