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 /
This question was closed Mar 25, 2014 at 08:31 AM by Fattie for the following reason:

Duplicate Question

avatar image
0
Question by pjlx911 · Mar 25, 2014 at 07:15 AM · rigidbodydoorkeyistrigger

isTrigger door issues

Hello,

I am having a little dilemma. I am working on a game and I have pretty much everything set UI wise. It's a neat 1st Person Puzzle/Adventure game I've been working on. I have keys, they have scripts, and once the player goes through the onTriggerEnter, the key disappears, a bool (hasKey) goes true, and a keyCount increments by one.

That's the easy part. The hard part is trying to use the newly-gathered key to open a door automatically. I have the door a cube, I have a box collider, marked it as isTrigger, and gave it a RigidBody (like the key, btw).

Here's the awesome part, I think this is a Unity deal (correct me if I'm wrong), but it seems that every object that is isTrigger true, the player can pass right through it. This makes it a pain due to the fact that I would rather have it so that the key opens the door (and the player does NOT pass through the door as if it was some sort of ghost door).

I have been looking EVERYWHERE to try to figure out a working fix for this, but I'm not coming up with anything that works. Could I ask for some help, please?

I am attaching a code to the door so that the door handles all the necessary leg-work (as it would make more sense since the door will have the RigidBody component). Thanks, again, for any help.

 using UnityEngine;
 using System.Collections;
 
 public class DoorTrigger : MonoBehaviour {
     
     
     void OnTriggerEnter(Collider other){
         
         
         if (Timer.hasKey && Timer.keyCount > 0){
             collider.isTrigger = true;
             Destroy(gameObject);
             Timer.keyCount--;
         }
         
         //if keyCount == 0
             //Do nothing
         if (Timer.keyCount <= 0){
             
         }
     }
 }

 
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 ShadoX · Mar 25, 2014 at 07:39 AM 0
Share

Why use a trigger? Why not just perform the check on a collision ? Or have 2 objects, 1 being the trigger, the other 1 being the door and when the key enters the trigger you could call some function on the door to unlock/open it.

1 Reply

  • Sort: 
avatar image
0
Best Answer Wiki

Answer by Juan73908 · Mar 25, 2014 at 08:01 AM

The answer to this is fairly simple.

Create another collider that isn´t trigger as a child of the door. The trigger collider should be sightly bigger, than the door collider.

When you want to open the door, remember to destroy, or deactivate the collider.

I cannot put code here, because everything is done in the inspector more or less

Good luck =)

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 pjlx911 · Mar 25, 2014 at 09:42 PM 0
Share

Thanks so much. Fixed all my problems. If I could vote, I would not only thumbs up, but would also sign in under different names to up vote you as well! :D

Follow this Question

Answers Answers and Comments

22 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

Related Questions

Rigid body Door requiring a key? 0 Answers

Problems with key script 0 Answers

Opening Door with Key 1 Answer

Rigidbody bounce or character controller istrigger issues 0 Answers

How to: make a user press a combination of buttons to play an animation. for example door open. 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