Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 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 /
  • Help Room /
avatar image
0
Question by MrQoZy · Oct 06, 2016 at 02:51 AM · door

door problems

hello everyone. so the code works but when the door opens its stretched out or it shrinks. depending on the angle. can any one help or give an alternate code to a doornot changing its size! thanks (please note im using a model for the door) so not a simple cube

// Converted from UnityScript to C# at http://www.M2H.nl/files/js_to_c.php - by Mike Hergaarden // Do test the code! You usually need to change a few small bits.

 using UnityEngine;
 using System.Collections;
 
 public class dddd : MonoBehaviour {
     //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
     public float  smooth= 2.0f;
     public float DoorOpenAngle= 90.0f;
     private bool  open;
     private bool  enter;
 
     private Vector3 defaultRot;
     private Vector3 openRot;
 
     void  Start (){
         defaultRot = transform.eulerAngles;
         openRot = new Vector3 (defaultRot.x, defaultRot.y + DoorOpenAngle, defaultRot.z);
     }
 
     //Main function
     void  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("f") && enter){
             open = !open;
         }
     }
 
     void  OnGUI (){
         if(enter){
             GUI.Label(new Rect(Screen.width/2 - 75, Screen.height - 100, 150, 30), "Press 'F' to open the door");
         }
     }
 
     //Activate the Main function when player is near the door
     void  OnTriggerEnter ( Collider other  ){
         if (other.gameObject.tag == "Player") {
             enter = true;
         }
     }
 
     //Deactivate the Main function when player is go away from door
     void  OnTriggerExit ( Collider other  ){
         if (other.gameObject.tag == "Player") {
             enter = false;
         }
     }
     //@youtube.com/user/maksimum654321
     //www.warmerise.com - check this game
 }


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 alexanderameye · Oct 27, 2016 at 12:01 PM 0
Share

if you simply need some working doors, you can check out this asset I created:

https://www.assetstore.unity3d.com/en/#!/content/38694

0 Replies

· Add your reply
  • Sort: 

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

75 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 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 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 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

trying to make my fps controller go through a wall with a doorway the wall has a mesh collider how do i adjust to go through the door 0 Answers

Open/Close Door only if player is near the Door 1 Answer

Door open/close sound effect?? 0 Answers

C# - How can i solve this door problem in script? Can someone help me? 1 Answer

Help: My doors won't work properly >< 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