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 Auto-Bot · Apr 29, 2014 at 10:49 PM · audiosounddoor

This door script causing door to go crazy?

 //Make an empty game object and call it "Door"
 //Rename your 3D door model to "Body"
 //Parent a "Body" object to "Door"
 //Make sure thet a "Door" object is in left down corner of "Body" object. The place where a Door Hinge need be
 //Add a box collider to "Door" object and make it much bigger then the "Body" model, mark it trigger
 //Assign this script to a "Door" game object that have box collider with trigger enabled
 //Press "f" to open the door and "g" to close the door
 //Make sure the main character is tagged "player"
 
 // Smothly open a door
 var smooth = 2.0;
 var DoorOpenAngle = 90.0;
 var opening:AudioClip;
 private var open : boolean;
 private var enter : boolean;
 
 private var defaultRot : Vector3;
 private var openRot : Vector3;
 
 function Start(){
 defaultRot = transform.eulerAngles;
 openRot = new Vector3 (defaultRot.x, defaultRot.y + DoorOpenAngle, defaultRot.z);
 }
 
 //Main function
 function Update (){
 if(open){
 //Open door
 transform.eulerAngles = Vector3.Slerp(transform.eulerAngles, openRot, Time.deltaTime * smooth);
 }else{
 //Close door
 transform.eulerAngles = Vector3.Slerp(transform.eulerAngles, defaultRot, Time.deltaTime * smooth);
 }
 
 if(Input.GetKeyDown("e") && enter){
 open = !open;
 if(enter){
        audio.Play();
          }
 }
 }
 
 function OnGUI(){
 if(enter){
 GUI.Label(new Rect(Screen.width/2 - 75, Screen.height - 100, 150, 30), "Press 'E' to open");
 }
 }
 
 //Activate the Main function when player is near the door
 function OnTriggerEnter (other : Collider){
 if (other.gameObject.tag == "Player") {
 enter = true;
 }
 }
 
 //Deactivate the Main function when player is go away from door
 function OnTriggerExit (other : Collider){
 if (other.gameObject.tag == "Player") {
 enter = false;
 }
 }

What could be causing this: http://gfycat.com/UnpleasantSelfreliantHairstreakbutterfly

It's easy to replicate. I go to the door, open and close it a few times as normal, walk away, then come back and try to open it and this happens.

Comment
Add comment · Show 1
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 Klarax · Apr 30, 2014 at 11:35 AM 0
Share

you might want to get iTween, i started using it and its blown my $$anonymous$$d. awesome for anything, including doors

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Apr 30, 2014 at 12:04 AM

Here is what I believe is happening. When you read 'transform.eulerAngles', these angles are derived from the Transform.rotation, which is a Quaternion. The angles you get out are not necessarily the ones you expect, and are not even the ones you put in. For example, run this script:

 transform.eulerAngles = Vector3(180,0,0);
 Debug.Log(transform.eulerAngles);

The results will be (0,180,180). Can you see how the changing representation might cause havoc with your Slerp code?

You can approach a fix in a couple of ways. First, you can calculate Quaternions for 'defaultRot' and 'openRot' in Start(). Then you can use those Quaternions in Quaternion.Slerp() to open and close the door.

The second solution is to maintain your own Vector3 and never read eulerAngles. Or only once at the start. The Slerp() done with your Vector3 and then the results assigned to eulerAngles:

  theRotation = Vector3.Slerp(theRotation, openRot, Time.deltaTime * smooth);
  transform.eulerAngles = theRotation;



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 Auto-Bot · Apr 30, 2014 at 07:08 AM

Thank you very much for your reply. I'm a little confused about how I should go about implementing your suggested changes though. If you would perhaps expand on that I would be extremely grateful. Thank you :)

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

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Sound play with the speed of the rotation speed of an object. 1 Answer

Make door play sound when you open and close it ? 1 Answer

Door Opens When Not In Trigger And Sound Help 1 Answer

help with multiple sounds 0 Answers

Audio doesn't play 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