Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 JaamiParvez · Apr 24, 2016 at 06:01 AM · collisioncollidercolliderscollision detection

How to get OnTriggerEnter effect without using isTriggered on Collider?

I did not set is Triggered on any of my two colliders, they both have rigid-bodies with Is-kinematic unchecked.

Now say I want to reset the other collider's position that collides with my collider, is it possible?

I know it can be done, if one of colliders have isTriggered checked. and using OnTriggerEnter() function.

but that way one of my collider just passes through other colliders. like this: https://media.giphy.com/media/OG38PwTPX23ZK/giphy.gif I tried this code with above settings ,(i.e IsTriggered unchecked on both collider). but it does not work.

 void OnCollisionEnter(Collision other)
     {
           if(other.gameObject.tag == this.gameObject.tag)
           {
             //reset this object position
           }  
   }

Comment
Add comment · Show 3
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 JaamiParvez · Apr 24, 2016 at 06:06 AM 0
Share

@Eric5h5 see If you could help!

avatar image tanoshimi · Apr 24, 2016 at 06:35 AM 0
Share

The first step in debugging any collision problems (and, pretty much, any callbacks) is to find out whether the method is being called. So as the first line in your method, just put this:

 void OnCollisionEnter(Collision other)
  {
      Debug.Log(this.gameObject.name + " collided with " + other.gameObject.name);

}

Does it print? If not, please post a screenshot of the inspector window showing the components attached to the objects (particularly the rigidbody and collider setup)

avatar image JaamiParvez · Apr 24, 2016 at 11:48 PM 0
Share

@tanoshimi Thanks for your interest!

Its working that way, I already tried that, but to be sure I again checked with your code.

    void OnCollisionEnter(Collision other)
          {
                if(other.gameObject.tag == this.gameObject.tag)
                {
                   Debug.Log(this.gameObject.tag+ " collided with " + other.gameObject.tag);
                }  
        }

but when I try that code above it does not work even when the tags of both objects(i.e the collider & collided with ) are same.

but it works when I use the the OnTriggerEnter() function with isTrigger checked on Collider component on one of the objects.

Thanks!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by AK-64 · Apr 25, 2016 at 04:30 AM

In this case, the object that you want to receive the collision should be non-kinematic, and the collider is trigger collider. [this is the ball at the bottom I assume]

The object that will trigger the collision should be non-kinematic, and the collider is NOT a trigger collider. [this is the ball that is falling I assume]

Remember, only ONE of them can be an isTrigger set to true.

Use a simple Debug.Log("here"); to check if there's any collision.

 void OnTriggerEnter(Collider other) {
     if(other.tag == GetComponent<Transform>().tag)
         Debug.Log("here");
 }

I tried this in my own test-box and it works perfectly. Make sure to mark this as solved if it answers your problem! :)

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

57 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

Related Questions

Strange issue with collider 1 Answer

Detect if a non-trigger collider is inside another collider 1 Answer

How to detect collision between 2 objects while checking are they the ones that need to collide? 1 Answer

How to reliably break contact/collision? 0 Answers

Why there is no Collider.IsTouching(...) ? 2 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