Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 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
0
Question by GigaRoid · Apr 15, 2014 at 01:06 AM · c#collisionrigidbodydoor

Door Not Colliding

I've successfully created a working door. It opens and closes when clicked and collides with the player fine. But when the player is running into the door right before the door is clicked, he goes right through.

This script is attached to the door, which is a transform child to an empty "hinge" object, which is being rotated.

 public bool Opened = false;
     bool bounced = false;
     public float SwingSpd = .01f;
     public float MaxAngle = .87f;
     public bool Swingin = false;
     
     //temp crap
     
     Quaternion CrappyDoo;
     
     void Start()
     {
         rigidbody.constraints = RigidbodyConstraints.FreezeAll;
     }
 
     
     //making sure door goes back if it hits a collider. (DUN DUN DUN)//
         
     void OnCollisionEnter(Collision NotUsingThis)
     {
         
         if (!bounced && Swingin)
         {
             SwingSpd /= 2;
             
             if (Opened)
             {
                 Opened = false;
             }
             else
             {
                 Opened = true;
             }
             
             bounced = true;
         }
     }
     
     void Update()
     {
 if (/*mouse click*/)
 {
 //toggle "Opened"
 Swingin = true;
 }
 
         CrappyDoo = transform.parent.localRotation;
         if (transform.parent.localRotation.y <= MaxAngle)
         {
             if (Opened && Swingin)
             {
                 CrappyDoo.y += SwingSpd;
                 transform.parent.localRotation = CrappyDoo;
             }
         }
         else if (Opened && Swingin)
         {
             Swingin = false;
             if (bounced)
                 SwingSpd *= 2;
             bounced = false;
         }
         
         if (transform.parent.localRotation.y >= 0)
         {
             if (!Opened && Swingin)
             {
                 CrappyDoo.y -= SwingSpd;
                 transform.parent.localRotation = CrappyDoo;
             }
         }
         else if (!Opened && Swingin)
         {
             Swingin = false;
             if (bounced)
                 SwingSpd *= 2;
             bounced = false;
         }
     }




I have no clue what's wrong with the code. The kinematic box is unchecked on the door's rigidbidy (otherwise it doesn't collide at all). I can't figure why it would ever not collide.

Comment
Add comment · Show 2
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 Salzmann · Apr 15, 2014 at 08:38 AM 0
Share

Ins$$anonymous$$d of showing you a way of fixing what you have, I will simply give you an idea on how to write a code for your door-job that cannot fail at this task. Ins$$anonymous$$d of using rigidbodies, just use colliders for doors and move the doors using localEulerAngels, which will give you the ability to directly manipulate each rotation axis in 360° circles ins$$anonymous$$d of the more complex quaternions.

 //example
 
 public GameObject Flag;
 public ButtonControllerScript $$anonymous$$yButton;
 
 void Update()
 {
 if($$anonymous$$yButton.isClicked)
 Flag.transform.localEulerAngles += new Vector3(0f,30f, 0f);
 }

Also, make sure that whatever shouldn't penetrate the collider is moving using physics correct movement, like rigidbody.AddForce() - but such a thing is self explenatory since otherwise all characters controlled by players could just move through walls and terrain.

avatar image jamesflowerdew · Apr 15, 2014 at 09:30 AM 0
Share

I think you're still moving the collider by moving it's root, because they share hierachy. A forced move (or roatate) will negate collisions. It may work better if your door is not a child of the "hinge". Do you need an angular costraint with a target rotation that you set for open and closed? freeze only the position and x and z rotations, you'll need y free.

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

23 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

Related Questions

Any way to ignore collision between rigidbodies and colliders/character controllers? 1 Answer

Freeze Gameobject's position on collision 0 Answers

How to hit gameobjects to go into the opposite direction of hit? 1 Answer

Rigidbody Interfereing with Multi Collider Health Script 2 Answers

Why can't my enemies walk up an incline? 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