- Home /
Check different collisions
Hi everybody, I want to know if is possible split the collisions check made by a collider set as "is Trigger" and other separate collider not set as "isTrigger".
To explain better the problem look at the image: I have my gameobject (1) L shape and I have to check his collisions with other objects.
Inside it has two box collider set as "is Trigger" (2) triggered and a wrapper surrounding collider (3) not set to "is Trigger" but i need it to simplify the drag process of the object.
It's possible in the function OnTriggerEnter, OnTriggerStay and OnTriggerExit exclude the wrapper collider?
Thanks in advance!
All you need is a Reference to the Trigger you dont want to detect, whenever those Functions detect that a collision is made with that Trigger, just ignore it since you dont want anything to happen with that particular Trigger.
If I understand the problem correctly, you probably just want to put collider GameObjects in different layers (and set the Physics Project settings to not collide your wrapper collider with whatever). In your input raycasting, only specify those layers you want to raycast against.
Or you can just RaycastAll and iterate through hits to find the one you need.
Sorry for the delay in response, basically I have this GameObject that is instantiated via script, and then I can't put colliders on different layers as they are already contained in it. I could keep the collider that should not do collisions always in the last place of the other colliders in the inspector and create a script that excludes collisions from the last collider (i can use GetComponents) but I don't know how to set this script and if it's possible, could you help me?
Have you tried Edit->Project Settings->Physics->Layer Collision $$anonymous$$atrix? You can set up which layers are supposed to collide with which other layers. And you can easily change which layer the game object is on with gameObject.layer
.
Answer by exp626stitch · Dec 16, 2020 at 06:50 PM
@xproject2013 Try using 3 objects,
your gameobject (no collider)
checking for collisions (2 colliders)
dragging (trigger collider?)
All paired to a master gameobject. When you want to do something with those collisions, acsess the children, and do what you want to do with them. (Might want to set main gameobjects position to the childs position, using)
public void Update() {
transform.position = child.transform.position;
//Disclaimer: this might not work, I have not tested it
}