Hi all, I’ve a gameObject with a sphere collider attached.
When it collides with some object of type A, the result would be a typical physical collider.
When it collides with some object of type B, the result would be very different from a physical collider, so for example one game object would disappear and the other one get bigger …
So it seems like a mix of a physical collider and a trigger.
If i check the trigger flag in the Inspector, I can perfectly create the second scenario, but not the first.
The main factor to decide to use a collider vs trigger is whether things should bounce off of it and it bounces around.
For example, say you want a pickup to wink out when you hit it. Either collider or trigger will work fine for that. Then decide trigger/collider by if enemies should pass through w/o picking it up, or bounce off.
If the player checks for collisions (or triggers – if a collider hits a trigger, the collider’s onTrigger will also fire,) use tags:
void OnCollisionEnter(Collision col) {
if(col.transform.CompareTag("typeB") { ... grow me, tPort col, etc... }
... same for typeA ...
If you want some objects to always pass through each other, but otherwise be solid, can use the physics layer system. But that will make them completely ignore each other. They won’t even register OnCollision. Your program can use Physics.IgnoreLayerCollision to turn it on/off. For example, grabbing a power-up could allow players to pass through red walls for 8 seconds using P.ILC, twice.
Hmmm, I still cannot understand. I’ve understood that the physics layer system is not good for my purposes.
So, let’s summarize in other words:
Object X can collide with other objects, for example object A and object B.
When X collides objectA the result must be a typical physical collision.
When X collides objectB the result must be dictated by a behavioral function, so for example the result could be that object X get bigger, and objectB change color.