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 zefrof · Feb 09, 2013 at 10:26 PM · triggerontriggerentercollide

how to collide while having a trigger?

I have a script that uses OnTriggerEnter to detect a collision. The problem is the thing it collides with goes right through it. Is there a way to use OnTriggerEnter and not have the thing it collided with go through it?

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

2 Replies

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

Answer by ThePunisher · Feb 11, 2013 at 09:02 PM

The trigger functionality is simply for the purpose of being notified when a rigidbody has entered a particular area covered by a collider, meaning there won't be collisions with the collider.

What you want to do is disable the isTrigger checkbox on the collider and define the OnCollisionEnter method in your script. Like this:

http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnCollisionEnter.html?from=Collision

Then, you will have your collision handled while being able to script something once the rigidbody has entered the collider.

You need to make sure that your Player/Object has a rigidbody and the object it is colliding has a collider component. Also, make sure the script with the OnCollisionEnter is on the object with the collider.

Comment
Add comment · Show 10 · 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 zefrof · Feb 11, 2013 at 10:40 PM 0
Share

Did as you said; is Trigger box is unchecked, the player has a rigidbody, the object it collides with has a box collider, and the code looks like this:

 void OnCollisionEnter(Collision collision) {
         Debug.Log("Collision Detected");
         
         if(rigidbody.gameObject.tag == "Weapon") {
             Debug.Log("Damage Delt");
             EnemyLife -= Damage;
         }
 }

When I add the rigidbody to the player it starts acting strange. The y axis will just keep getting larger and when I lock the y axis it moves erratically.

avatar image ThePunisher · Feb 11, 2013 at 10:54 PM 0
Share

Oh woops, forgot to tell you to uncheck the uses Gravity checkbox on the rigidbody.

avatar image zefrof · Feb 11, 2013 at 10:57 PM 0
Share

The player still floats. :( On another note does everything else look good?

avatar image zefrof · Feb 11, 2013 at 11:15 PM 0
Share

I put the rigidbody on a child and shut off gravity. The player moves normally now, but the debug and if statement don't run.

avatar image ThePunisher · Feb 13, 2013 at 12:23 AM 0
Share

Hmm, did you make sure isTrigger is disabled on the collider that has your debug statement script?

Show more comments
avatar image
0

Answer by adrenak · Feb 10, 2013 at 05:55 AM

Use OnCollisionEnter in the script and disable the 'isTrigger' checkbox so that it becomes a normal collider. When the 'thing' collides, the script will do its job.

PS : Just keep in mind that the OnTriggerEnter function returns a Collider variable, where as the OnCollisionEnter returns Collision variable, just something that people forget sometimes. Look it up in the scripting manual.

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

11 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

Related Questions

Increase Speed 1 Answer

Trigger and Collider Issues 1 Answer

OnTriggerEnter gives me error? 2 Answers

Disable Mesh Collider Trigger 1 Answer

OnTriggerEnter fails to activate 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