I’m trying to make a projectile (Prefab) shoot out of a car (Prefab) and be able to detect collisions with other objects, mostly other cars. For the hooks themselves I have the Prefab on layer 10 and do a Physics.IgnoreLayerCollision so the hooks will ignore their own collisions, this works fine as far as I can tell. However when I instantiate the hook it won’t ignore the collision with the car that spawned it. Here I try to do this:
Transform createdProjectile = (Transform)Instantiate(HookTemplate, transform.position + directionVector, transform.rotation);
Debug.Log("CarAll collider: " + collider.enabled);
Debug.Log("createdProjectile collider: " + createdProjectile.collider.enabled);
Physics.IgnoreCollision(collider, createdProjectile.collider);
But when I drive my car into the hook it collides and gives an error:
Ignore collision failed. Both colliders need to be activated when calling this IgnoreCollision UnityEngine.Physics:IgnoreCollision(Collider, Collider) ThrowHook:Update() (at Assets/ThrowHook.cs:43)
As far as I can tell I’m doing it exactly as Unity - Scripting API: Physics.IgnoreCollision says to do, but something is going wrong.
Any help would be appreciated. Thanks.