- Home /
OVR Grabbable causes object to ignore OnCollisionEnter/Exit
I have a very simple script attached to a cube the only thing in the script is:
void OnCollisionEnter(Collision collision) {
Debug.Log("We hit something");
}
When i start the game the Debug message gets put in the console. But when I grab the cube and move it away then put it through the cube it was on in the first place the message doesnt get printed. If I then let go of the cube and drop it either on the first one or onto the plane the message is then printed again.
I've tried all 3 modes for collision detection on the rigidbody and haven't been able to find anything that relates to this very well on google.
I'm running Unity 2018.2.21f1 (I did have 2018.3 but I had to downgrade because something wasn't working right I think I couldn't grab anything at all and its a known issue or something like that I cant remember)
I tried this on one of my projects using OVRGrabbable and I did receive the message in the console when a collision occurred, even if I was holding the grabbable object. I don't believe that it is OVRGrabbable suppressing the callback but I don't know why that would be occurring. It could have something to do with the some or all of the rigidbodies kinematic setting as true.
I just found out that, that is what is causing my issue is the object being set to $$anonymous$$inematic = true
If I remove that from the OVRGrabbable script the collisions work normally. But does yours do this (Set everything to kinematic = true) and you still get the collision properly? @dtrevillyan
Answer by dtrevillyan · Mar 24, 2019 at 01:20 PM
@Rusherz, actually I didn't try it. I did see in the scripting API for the OnCollisionEnter callback that at least one rigidbody needs to be nonkinematic. That is why I suggested checking the setting. Glad to hear it is working now.
Answer by DDorukA · Apr 06, 2019 at 12:58 AM
I am using OnTriggerEnter with tags instead of OnCollisionEnter and it works fine for the most cases. Here is an example that is working for my project.
void OnTriggerEnter(Collider other)
{
int randomClipNumber = Random.Range(0, SwordCollisionAudioClips.Count);
CollisionAudioSource1.clip = SwordCollisionAudioClips[randomClipNumber];
if (other.gameObject.CompareTag("Sword"))
{
CollisionAudioSource1.Stop();
CollisionAudioSource1.Play();
Play Vibration
VibrateRightController();
}
if (other.gameObject.CompareTag("Player"))
{
other.gameObject.GetComponent<PlayerBeh>().TakeDamage(weapondmg);
Play Vibration
VibrateRightController();
}
}