Water freezing problem

So, In my game I have an object called a “Water Freezer”.

When you push it into a body of water, it’s supposed to turn it into ice.

The first time I made it, it only froze the water it touched.

So I added the “Pick all objects” condition, And it worked.

But then I realized I want it to freeze one body of water at a time. If I use the pick all objects Condition, It’ll freeze all bodies of water in the scene, and I don’t want that. I want it to just freeze the body of water it touches. It’s worth noting that each square of water it it’s own sprite, not a tiled sprite.

How can I make it so that it only freezes the body of water it touches?

Here are my events:

A simple way is to give the freezablewater objects a variable, say named “WaterBodyId”. Using a different id for each body of weater, give each freezablewater objects that make up a body of water the same WaterBodyId. When the ice collides with a freezablewater object, get it’s WaterBodyId to and use that to identify all the other freezablewater objects that make up the body of water.

An easy way to give each freezablewater object of a body of water the same id is to set one in the editor, then copy and paste the rest - the WaterBodyId should be the same in each copy.


A more advanced way will be to freeze the first freezablewater object the ice collides with, then check around that for other freezablewater objects, change their animation, and check around each of them for freezablewater objects, and repeat the process until no more freezablewater objects are found. This is a bit more involved and a reasonably advanced technique, but means you don’t have to keep track of the different WaterBodyIds.

2 Likes

Could you show me an example of the events?

For the ID variable one.

I don’t understand what’s wrong with your first try

@arthuro555 , think OP means it only freezes the freezablewater object it touched, and not all the objects that make up the body of water.


@takratzer, here’s a snip that assumes each freezablewater object has the variable WaterBodyId:

I haven’t included the icemelt object creation, but that would happen in the 2nd event in my screen snip.

You mean you want to make sure that at all times that only one object can be affected? A for each event, and a boolean variable that you set to false before, to true in the for each event and check for being false in the for each event should do the trick.

Please don’t use IDs, they are not a good practice, they usually only add unnecessary complexity.

My understanding is OP wants all the freezablewater objects that make up the body of water to change animation to frozen, not just the one that the water freezer touches.


I understand there are other ways of solving it, but for me using IDs is the easiest solution in this case. I had suggested another solution that involved repeatedly iterating over all the neighbouring objects of each affected object until there are no further affected objects. But this I feel is too difficult to grasp at this stage.

However, if you have another solution, I’m all ears. I know there will be other ways of using GDevelop that I’m not aware of, and I’m interested to read about them.

Ah I think i finally understood the problem. Personally, I would probably use an IDs indeed, as this is not a UID but a shared ID describing relationships and that is ok to use, but I can think of arguably easier ways.

For example, you could make a “Grouping object”, where you put each instance in a way that they cover the body of water. Then, collision check the touched water with that grouping object, repick all water objects, and collisions check the water with the picked grouping object, and you have picked all the objects that are part of the body of water.

2 Likes

@arthuro555 @MrMen Thank you to both of you. You helped me fix it!

1 Like