- Home /
GameObject sometimes collides, but sometimes goes through each other.
I am working on a game that involves spawning in bacteria prefabs. They have a rigidbody and capsule collider component, with Collision set to Continuous Dynamic. I have isTrigger turned off to allow for Unity physics engine to take care of the collisions. The bacteria are instantiated at runtime and move through the rigidbody, with rb.velocity (kinematic is turned off).
My problem is that the objects are not colliding reliably. Sometimes they pass through each other, sometimes they bounce off (I added a physics material to the collider). It seems, after running the scene several times, that the bacteria have to pass through another bacteria, and once that occurs, the collision for the two bacteria start working, as the problem goes away a several seconds after I start the game. This action still seems to happen randomly, though, as a few bacteria just don't collide at all, so I am quiet confused as to what's causing the collisions to be ignored.
I heard that Unity has this thing where it disables collisions if any two objects are on top of each other and turns it back on when they part, but I don't think that's the issue since there are multiple bacteria on the screen, and it is well by itself yet the problem still occurs.
To add on, I do have different prefabs that are supposed to interact with the bacteria. They have sphere colliders and rigidbodies as well, but they experience the same problem.
If anyone knows the reason for this, or any solution, it would be very much appreciated. Thanks for the read!
$$anonymous$$ight not be the answer, but a few things that I can think of that might be causing the issue:
Some of the bacteria don't have colliders or have the collider component set to off.
The size of the collider is smaller than the bacteria mesh, making it seem as if the bacteria are phasing through each other.
Lag from the amount of stuff that is going on in the game.
A problem in the script
I'm pretty new so if those aren't the issue, I'm not sure if I can offer any further assistance.
Your answer
Follow this Question
Related Questions
Weird collision with objects passing through each other 1 Answer
Rigidbody colliders 1 Answer