Layer-based collision detection
Layer-based collision detection An automatic process performed by Unity which determines whether a moving GameObject with a Rigidbody and collider component has come into contact with any other colliders. More info
See in Glossary is a way to make a GameObject The fundamental object in Unity scenes, which can represent characters, props, scenery, cameras, waypoints, and more. A GameObject’s functionality is defined by the Components attached to it. More info
See in Glossary collide with another GameObject that is set up to a specific Layer or Layers.
The image above shows six GameObjects (3 planes, 3 cubes) in the Scene view An interactive view into the world you are creating. You use the Scene View to select and position scenery, characters, cameras, lights, and all other types of Game Object. More info
See in Glossary , and the Layer Collision A collision occurs when the physics engine detects that the colliders of two GameObjects make contact or overlap, when at least one has a Rigidbody component and is in motion. More info
See in Glossary Matrix in the window to the right. The Layer Collision Matrix defines which GameObjects can collide with which Layers.
In the example, the Layer Collision Matrix is set up so that only GameObjects that belong to the same layer can collide:
- Layer 1 is checked for Layer 1 only
- Layer 2 is checked for Layer 2 only
- Layer 3 is checked for Layer 3 only
Change this to suit your needs: if, for example, you want Layer 1 to collide with Layer 2 and 3, but not with Layer 1, find the row for Layer 1, then check the boxes for the Layer 2 and Layer 3 colums, and leave the Layer 1 column checkbox blank.
Источник
Collision detection not working unity
First, I know that this question has been asked a lot, but I cant find a solution, so mi problem is, Im making an educational game, and I have a vein and the blood flow (with many box colliders) and a single blood cell (also with a box collider) however i want the cell to destroy when it reaches the wall collider, but it doesn’t it just stays there, here is the project!
(cant upload images because of my reputation, sorry)
The collider where I want to destroy my cell is the pink collider, however when it touches it it just does nothing, here’s my script
Also, here is the AddForce script
thanks for your help guys! 😀
4 Answers 4
It can be several things, whether you are using OnTriggerEnter or OnCollisionEnter :
Missing RigidBody (the most common). At least one of the GameObjects involved needs to have a RigidBody. (check if at least one of them have a RigidBody attached and, if you are using OnCollisionEnter , does not have the «Is Kinematic» checked). See the below collision matrix for more information.
Missing tag. The GameObject from collision does not have a «Collider» tag (try to remove the if statement to test it) (to compare tags, use collider.gameObject.CompareTag(«Collider») , it has a better performance)
Undetectable collision. The physics Layer Collision Matrix is set to not detect collision between the layers the objects are (enter Edit > Project > Phisics and check if the encounter of the layer of both GameObjects are checked inside Layer Collision Matrix)
Wrong Collider configuration. one or both of the GameObjects have a small/wrong placed or absent Collider (check if they both have a Collider component and if their size are correct)
If it’s working, you should be able to press play and drag one GameObject into the other one and your Debug.Log will appear.
As an advice, use tag names that better describe the group of GameObjects that will be part of it, like «RedCells» or «WhiteCells». It’ll be easier to configure the Layer Collision Matrix and improve the performance of your game.
Another advice: for colliders that just destroys another GameObject (don’t react, like bump or actually collide) I use triggers. That way, the collision between them will not alter anything in the remaining GameObject (like direction/velocity/etc). To do that, check the Is Trigger in the Collider and use OnTriggerEnter instead of OnCollisionEnter.
Источник