After looking at this post, I decided to declare colliders in the constructor and change my scripts to find them. This has not worked.
My code is -
public Collider collider1;
void OnTriggerEnter(Collider other)
{
if (other == collider1)
{
print("A check to see if Trigger Enter has been called");
}
}
The code is not creating errors. I have correctly selected the collider in the inspector, which is set to Is Trigger.
I would appreciate if somebody could possibly tell me where I am going wrong. Thanks.
Box Collider at the bottom is dragged into Queue Box, which is beneath the Points Array. All is in the Inspector. I donât know what is meant by âProject hierarchyâ or âScene hierarchyâ. But in this case, it would only apply to this particular scene.
One of the objects that intersect has itâs collider set to trigger
@OP: What type have you declared the Queue box as? If the type is Collider, you might have assigned the sphere collider you want for the attack sphere in the queuebox slot.
If thatâs the case, you can drag the box collider directly from the inspector instead of dragging it in from the hireachy - just click on the âBox Colliderâ text, and drag into the Queue Box slot.
By the way, you donât need to check the tag. Youâre checking if itâs exactly one collider, which means that the tag is already a given.
Heâs dragging the Box Collider[Trigger] on the same GameObject shown in the pic to be the queueBox, then expecting OnTriggerEnter to be fired when a Trigger enters it which does not happen.
queueBox needs to not be a Trigger if it is intended be used to activate a different Trigger.
@Baste , I have tried declaring Queue box as a BoxCollider and a Collider before now and both times I havenât had success. I am dragging the item in the Inspector onto the slot. If youâre able to see in the small image, the cuboid shaped green image is in the Queue box slot, while the spherical shaped image is in Attack Sphere. My object has no other sphere/box colliders.
@LaneFox , If the colliders arenât set to Is Trigger, then the objects that they are looking for do not intersect, as theyâre solid. Nothing is happening when these solid colliders hit what theyâre looking for.
Are there any images/more information that I can provide, as I suspect I havenât provided enough.
If you could throw together a small example project showing what youâre trying to do not working, I could take a look and tell you what youâre doing wrong.
Wait, attackSphere is on the skeleton footman, right? But youâre checking if the collider you collider with is the attack sphere, and has the tag âPlayerâ. Those two things donât seem to me like they would the true at the same time.
What are you trying to do with that if-check? Are you checking if you have collided with the player character? Or if you have collided with the enemy?
void OnTriggerEnter(Collision col){
// if an object collides with an tag
if (col is SphereCollider && col.gameObject.tag == "") {
// your code
}
// or an object collides with an name
if (col is SphereCollider && col.gameObject.name == "") {
// your code
}
}
I have it working now. The package from @LaneFox was really useful and I immediately saw my fault. Thanks @Baste , for again helping me out with an issue, your words made a lot of sense.
The collider was attached to the Skeleton, while I said other should have the tag of Player (a separate object). Having one statement as true, and the other untrue was the reason it wasnât being called.
When declaring the AttackSphere should be on the Player, everything works and compare tag is needless.
I do question how it is possible to use more than one collider type on the same object properly. I just added an extra Sphere Collider to the player, set it to is trigger and I cannot see any way of distinguishing one from another in the inspector, in fact only one collider is being shown. Can anyone answer how to use multiple colliders of the same type (Box, Sphere, etc.) on a single object?
Edit:
Child objects with different colliders would suffice, and I am guessing that is how it is done.
You can have all sorts of colliders on the same GameObject. To link others than the top one in the inspector stack: Create another inspector tab that you lock, then drag and drop.