Compare two specific instances of an object?

I asked this question before but I feel like I didn’t explain myself properly, which is why I got no answer back.
In order to remedy, I’ve made a more comprehensible and charming example.

Everyone knows that chicks want to walk with their chicken mother, and that chicks should probably wait for the car before they cross the road. Here’s a recreation of this scenario in Gdevelop.

chicken

But this isn’t really appropriate chick behavior. Chick are supposed to be waiting in a line, kinda like this.

And I can’t seem to make them wait like this. My solution was that, they’re not supposed to collide with one another, so they stop when they’re too close. To be more precise, the one that stops should be the one whose X value is lower between the two chicks that are close to one another.

But this doesn’t work, because it doesn’t only check for the X value of the chick that’s too close to, but also for the third, meaning that I get this weird behaviors.

fsfs

How can I fix this?

Comparing instances of the same object is hard, especially collisions. What you need to do is create a new, hidden object (‘ChickCollider’ for example) and then attach that to each Chick instance (using the Sticky extension and the Link Objects behaviour). Then you can check if a Chick collides with a ChickCollider and that should work better.

See this comment for a better explanation:

For that kind of objects in line behavior, I like to use an instance variable to change the offset each instance stops moving. For example, I’d put as the distance in the distance condition 32 + Chick.Variable(ChickOrder) * (Chick.Width() + 5). Then, I can give one chic the order 1, another 2, and the next one 3… And they’ll be stopping one next to the other with a gap of 5 pixels between them :smile:

1 Like