- Home /
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
}
}
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)
@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!
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! :)