Trigger resetting?

I don’t know exactly how to word this thread title. So please forgive me if it’s kind of misleading.

Let me dive right in here.

I have two triggers here. There can(and will be) more. This is a setup I have for creating a board game where the player will place pieces down on the board, and the triggers represent the possible placement areas on the board.

The two squares there are the triggers, resting side by side. The blue circle represents a board piece that is being placed on the board beneath the triggers(using raycasting).

When the OnTriggerEnter() event gets called after I place the piece on the board, it checks to see if the bounds of the trigger contain the center point of the game piece.

    void OnTriggerEnter(Collider other)
    {
        if (this.collider.bounds.Contains(other.bounds.center))
        {
             // Do some stuff
        }

Even though both triggers are being set off by the game piece, only one of those triggers actually does anything. That of course being the one trigger that actually contains the very center point of the bounds on the collider.

This all works great. However, the problem arises when I try to click to move the piece into the adjacent trigger spot. Seeing as how the trigger was already previously set off before, it doesn’t get set off again and thus executes no code.

I could use OnTriggerStay() instead of OnTriggerEnter() and create some extra variables and stuff to determine state. However, I wish I didn’t have to do this. I wish there was a way I could make the triggers unaware that the game piece was already inside them when I move it again. That way it would set off the trigger again and I wouldn’t have to bother with all those extra variables and the trigger wouldn’t be executing a million times a second(or however many it is).

Is there a way to accomplish this? Am I going about this in an entirely inelegant way and there is another better way?

The solution for this depends a lot on your game and the object sizes and well, how much coding you want to do, but here’s how I’d do it:

  1. Make the collider for your game piece really small.

You can setup multiple colliders and use collision ignore rules if you need full size colliders for physics ect.

  1. Add a counter variable to the OnTriggerEnter event, so it’ll add triggers++ on enter and remove triggers-- on exit so you know how many triggers any given game piece is intersecting.

  2. OnUpdate if your “triggers” variable is large than 1, lerp/move the game piece towards the centre of the trigger the price’s center point is contained within.

This should slide the piece a little towards the middle of the trigger area when you place one near a border. The smaller you make the collider, the less it’ll slide it.

You my friend, are a genius! It’s amazing how a single mind can get stuck in a logical rut and be lacking in creative ideas.

As I mentioned above. You are a genius! Not because this is some wildly elaborate design mechanism… but rather because it is so simplistic.

I never even stopped to think about making a SMALLER COLLIDER. My mind was only thinking about how to make this work with the full sized collider. Because this is going to be a game of craps, there are some areas on the board that will have the chips potentially overlapping due to small placement areas. This is even more prevalent in a roulette game where it is actually required due to how the game plays.

The smaller collider idea you have is excellent. It will let me be able to have the player place it anywhere and still register properly without me having to deal with OnTriggerStay which is the way I currently have it implemented and it has all those needless calculations every frame. I can then use your LERP idea to give the player a hint that he needs to keep his tiles closer inside the proper betting area.

You sir, have made my day. Thank you again.

Ugh.

I have everything else in place as far as maintaining which triggers and stuff the pieces are in, and logic for it to move it out of the extra triggers.

However, I am completely stuck right now in dealing with multiple colliders. Having the main collider for physics interactions, and a smaller collider as a child of the geometry for trigger interaction.

Having trouble getting the new collider to work properly with the triggers without interfering with the rigidbody of the main collider and other complications. One of the other things is that when sliding the collider along the ground it’s all jittery and freaks out. I’m trying to aim for a smooth slide.

AGH! Driving me nuts.

Change the things that the smaller one can collide with. make sure that the bigger collider can’t collide with the smaller collider, and vise-versa.

I read somewhere in the documentation and I think on the forums as well that child colliders do not collide with parent colliders.

Is this not true?

Oh well it’s Christmas tomorrow. I better get some sleep.

I’m not sure. I’ve never had an instance of the whole colliders thing. But you should change them anyways. Just to be safe. You never know! :smile: