Main reasons your Object is not colliding with other object in Unity3D

 Many new unity programmers think that they have learned how to move the gameobject, e.g., using the translate method or by changing the position of an object. Now they can do anything related to movement without properly learning movement mechanics or the physics engine of Unity3D.

And then, we regularly see different questions on different programming forums like 

  1. My object is not colliding with others
  2. Character passing through the floor,
  3. Obstacle detection is not working, 
  4. Car is driving through the walls
  5. My player is not colliding etc.,

In most cases, these problems happen due to improper use of movement methods with a rigidbody object. In this post we learn the main reasons that why your object is not colliding with other objects. 

Main Checklist to ensure Proper Collision:

Obviously, when the collision with two objects is not working, then, there are collider-related issues involved:

  1. A collider is not available on the object(s).
  2. Or the layer collision is off for two specific layers.
  3. Or the collider has the isTrigger check active which means the trigger will work but the collision of the object will not happen. And it will pass through the object.
Also, make sure that you have enabled the layer collision of respective colliding objects under layers collision or collision matrix. This option is available under  Edit -> Project Settings-> Physics category :
Finally, I will highly recommend you check the Unity official collision table where you can see when the collision or trigger will happen when two objects collide. These collision matrix will explain when collision will perform.
When Collision or trigger will detect - table by unity
Unity Object collision Matrix



Now, if your physics still not working properly even after checking the above-given points, there are two main reasons. The first one is more important and more often:

Don't Touch The Transform - Use Proper way of Movement with Rigidbody:

The basic tip is that you should not play with transform whenever you want to use the physics system or the effects that required physics simulation. Yes, don't touch the transform like using the Translate method or changing the position. You should not directly interfere with the transform if you want to get proper physics effects.

Instead, you should use Physics Rigidbody functions like velocityAddForceAddTorque, and MoveRotation. By using these methods your objects will remain under the control of the Physics engine and you will not get weird physics/collision effects.

Model the Object on Real Scale:

The second thing which creates weird physics behavior is the size of a model/Game Object! If you read the official unity docs about rigidbody then, unity clearly mentioned:

If you find that your Rigidbody is not behaving exactly how you expect - it moves slowly, floats, or doesn’t collide correctly - consider adjusting the scale of your mesh asset

Unity doesn't encourage you to change the scale of your object instead, it will ask you to scale the object in your modeling tool at the real-world size. Like if you have a 2-meter-long character then, a Cube inside unity with a scale of 2 will be equal to your character size. The unity physics engine assumes that 1 unit in unity equals 1 meter. 

Let's conclude the things that at the first point make sure to check basic things, the collider, layers tagging, trigger check, etc., Then, make sure that you are moving the object with the right method of physics, and finally, make sure that the scale is correct.

Post a Comment

0 Comments