Collision detection for moving objects

I’m working with a student on a small puzzle map and am struggling with one of the interactive challenges student set up. Upon collision with a moving object, namely the spike at the end of the first corridor, the collision detection doesn’t seem to execute?

Student has a number of moving items that can end the game, so they are kept in a list like this.

I have tested this myself, and have had no issues with this method provided collision items are static:

Is this a issue with moving items, or are we both missing something in student’s code?

Many thanks :slight_smile:

Links:

Student’s full code

My test save

Hi Jas,

Can you make a copy and make it ‘remixable’ so we can see the coding?

Cheers

Hi @jas This happens because when two objects are very close together, the system may detect their collision events in a different order than expected. For example, it may register one object entering a collision area and then another object leaving it immediately after, which can cause the color to update incorrectly.

To better understand what’s happening, try adding some logging to check the order in which these collision events are being triggered.

enter CI0
enter CI1
leave CI0

Instead of only checking whether something is currently colliding, try keeping track of all objects that are touching the item. Add an object to the list when it starts colliding and remove it when it stops. Then, you can check whether the list is empty: if something is still touching the object, keep the new color; if nothing is touching it anymore, return to the original color.