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 dijital · Jun 02, 2013 at 10:24 AM · collidertriggercollidersontriggerenterontriggerexit

Make object react to certain triggers only

Hi, I have a scene with two different triggers attached to box colliders, one changes the gravity force and the other changes the angular drag of the player.

The problem is, when I hit any of the triggers, it changes both the gravity and the drag.

How in code do I get it to differentiate between the triggers? I thought I was by naming the box colliders and calling them in the script like below, but that doesn't seem to work.

     function OnTriggerEnter (DZone : Collider) {
         rigidbody.angularDrag = 0.4f;
         print("DRAG LOW DRAG LOW");
     }
     
     function OnTriggerExit (DZone : Collider) {
         rigidbody.angularDrag = 25.0f;
         print("DRAG HIGH DRAG HIGH");
     }

Any help would be appreciated.

Thanks!

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

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by fueldown · Jun 02, 2013 at 10:59 AM

You should compare the tags in order to differentiate between them.

     function OnTriggerEnter (DZone : Collider){
         if(DZone.tag == "TagOfObjectYouWantToReduceDragOF"){
            rigidbody.angularDrag = 0.4f;
            print("DRAG LOW DRAG LOW");
         }
     }
      
     function OnTriggerExit (DZone : Collider) {
         if(DZone.tag == "TagOfObjectYouWantToIncreaseDragOF"){
            rigidbody.angularDrag = 25.0f;
            print("DRAG HIGH DRAG HIGH");
         }
     }
Comment
Add comment · Show 3 · 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 fueldown · Jun 02, 2013 at 11:02 AM 0
Share

use DZone.rigidbody.angularDrag

ins$$anonymous$$d of

 rigidbody.angularDrag
avatar image dijital · Jun 02, 2013 at 12:51 PM 0
Share

Did the job! Thanks!

avatar image fueldown · Jun 03, 2013 at 03:03 AM 1
Share

Glad I could help. $$anonymous$$ake sure you mark it as an accepted answer if you think the issue is resolved.

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

15 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

Related Questions

How to use different and distinguish between different box colliders? 1 Answer

Compound Triggers with no intermediary exit calls 1 Answer

OnTriggerEnter/Exit called unexpectedly 2 Answers

How to use OnTriggerEnter with multiple triggered objects? 1 Answer

Trigger and Collider Issues 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