Is there a way to restrict a draggable objects from going out of bounds after putting them in an another draggable object?

I’m new at gdevelop and I want to make a pizza game, I want to know if there is any way where if you put the toppings(which are all draggable objects) to another draggable object which is my dough but when you move the whole dough the toppings will stay put, but still move the toppings freely with your mouse if you wish to do so.

Maybe this will do what you are after? Pin object to another multiple parents - a game example from the GDevelop game making app | GDevelop

1 Like

You can use the sticker behavior to stick one object to another.

Add the sticker behavior to your topping object.

With the topping use the conditions just dropped and trigger once with the action stick topping to dough

To unstick use is dragging with trigger once and the action topping unstick

Do you have more than one dough object at a time? If so, the stick event would also need the collision condition so it knows which dough to stick to. Add the condition collision with dough between the just dropped and trigger once conditions.

1 Like

Wow - so many functions I don’t know about! Nice one, Keith_1357!


Thank you so much! But how about the having one more dough object? My game does have the ability to have more than one dough at a time, but they just use one object, as I’m using the create object action. When I try to put a topping the other dough it doesn’t seem to stick, is it possible to make it stick to the other dough??

If you add a Collison condition

topping was just dropped
Topping is in collision with dough
Trigger once

Stick topping to dough

Conditions work like filters. Without a condition actions usually apply to all of the instances/objects. Some actions can only handle one object so it believe it usually uses the 1st object that was created.

In this example, I used **pick nearest ** Should you have 2 dough objects that the topping could collide with at the same time then it helps to pick the nearest. If it’s not possible for 2 to be that close then it’s not needed.

As I said. It’s like filters. The collision would pick any colliding objects and the nearest would pick the nearest out of those objects. Without the collision, it would pick the nearest among all of the instances.

The sequence of events is so important. If you used nearest first then it would only pick the nearest. Then if you checked for collisions it could only check if the nearest object was in collision with the other object.

1 Like

Thank you, I feel like I’m at your debt, though I have one more question. It goes out of topic, since it’s not about the toppings anymore but more on the dough. I have this board, when it collides with the dough, the dough will play a kneading animation. My problem now is that when it has it’s sauce now, when it collides the kneading animation plays, and is there also a way to restrict sauces from being clicked and changing the animations when it’s still in it’s dough form?

Here’s what I have in the events at the moment:

You can add the condition to check the animation’s name after the click and the collision with board so it knows which pizza and that there is a pizza.

sauce is clicked
Pizza is in collision with board
Pizza animation equals whatever it needs to be

If it was after the kneeding was done then you could check the animation and then check “animation finished” although it might be easier to follow the events if you add a “kneeded” animation and change it when the kneeding is done.

Pizza collision with board
Pizza animation equals kneeding
Pizza animation finished

Change pizza animation to kneeded

Then you could just check the animation name without checking for the finished. I think it would be more structured and consistent.

Same with pesto. If the sauce was needed then check if the animation is sauce with the collision event to pick the pizza on the board.

It’s probably best to either not give the player the option to add things out of sequence by hiding them or making them greyed out. Reminder hidden objects can still be clicked. Or give them some form of feedback. It could be a simple X over the object, a sound or some form of text.

It might be interesting to let them make it out of sequence then show them the ruined pizza and have them start over. That’s up to you. In a friendly way not mocking. Maybe with some humor.

1 Like

Thanks for the answer, I’ll try to do it tomorrow or later. I’m not sure if I don’t understand or just sleepy haha.

1 Like

Pleasant dreams. We’re here if you still have questions.

1 Like

Hey! I’ve run into some problems, what you’ve just recommended didn’t seem to work for me, and when I put a topping on said pizza, it sticks, but I can no longer take it off the pizza.

Here’s a clip of my game if it helps

Can you post a screenshot of your relevant events?

This is what I’ve done so far, I deleted the condition and action that you recommended for me since it didn’t work for me.

This is the other screenshot, since my account is still new, I can’t embed two images at once.

Does this version work?

These need to be separated. Drag the second to the left so it’s not a subevent. Right now, the collision only happens once, so the subevent can only happen on that frame.

I’m not sure if you want this to be an action and not a condition. I know, I chose the wrong one as well. Right now, it’s asking “is the z-order 10?” without any actions.

I don’t know why the dough is moving. When dragging objects, the top-most object should get priority. You could disable the drag behavior of the pizza after it’s added until it’s done. Set it to no to disable, yes to enable. You can disable the toppings when enabling the pizza. Once you add toppings, it would be tough to just click the pizza. Maybe you can use one of those board things. Whatever they’re called to pick-up the pizza. Either that or a button.

Here’s an example, it assumes there could be more than one pizza on the screen. Although, if that was the case you would probably need an event to select pizzas when adding sauce. Maybe make that draggable like a container of sauce. Drag and drop the sauce on the dough and then either delete the sauce container or move it back to its position.

Are you familiar with object groups? If you put the topping into a group then you could use conditions and actions using the group name that would apply to all of the toppings.

I can explain that more, if needed.

I fixed the topping problem, thank you for pointing it out. I tried doing your first solution but it didn’t work out. Also I thought of a way of making it easier for me, is there a way to limit the objects/instances? I thought of limiting the dough to one instead.

Here’s a clip of the gameplay

There are a lot of different ways. Yous could only keep 1 dough object on the tray at a time. Add another when the pizza is done.

You can use a variable to track the mode or a Boolean like MakingPizza. Set it to true when a pizza is added and false when done. Either use the variable to disable interactions or check the varaible when an action is attempted. Add MakingPizza is false I like Booleans. It creates easy to follow structure.

You could also check if there’s pizza on the board object. If there are multiple pizzas in the scene, you would need to use the NOT condition with pizza in collision with board.

If you have 3 pizzas. 1 on the board and 2 on a tray.
pizza collision with board would be true and pick the pizza on the board
inverted pizza is in collision with board would still be true and pick the pizza not on the board

The NOT condition inverts the result not the action.
So, NOT pizza collision with board would be true only if there wasn’t anything on the board.

It might be confusing but it works.

The easiest method would to just have one dough or pizza object on the first tray at a time. Then add a new one when the pizza is removed from the board.

1 Like

Is it okay if you elaborate on the topic more? I’m still very new on gdevelop and didn’t understand quite a lot. I have heard about booleans, but how I am supposed to incorporate it to my game? Sorry for the questions.

There are 3 main variable types. Numbers, strings and Boolean. 3 scopes scene, global and object. All the scope types are identical other than their scope. Either within a scene, within the whole project or within an object in a scene.

Booleans are either True or False. It’s kind of the way computers work. Like a single bit, either on/off or 1/0 or yes/no.

Booleans are useful for states or the status of something. Like Selected or isRunning or Locked. It helps to make the variable name descriptive and either an action or a question. Everyone has their own style.

Some people use integers for modes like 0 or 1. That’s fine. But DoorIsLocked is true is a little clearer to read than DoorIsLocked is 1.

Booleans are builtin to GDevelop everywhere there’s a toogle like **enable a behavior **

You can set a boolean to true/false , check it’s value or toggle it. Toggling is useful. It’s an action listed with the other variable actions. It toggles a value between true and false. Think of it like pressing a button or light switch. If on set to off, or if false set to true.

In this example an object called tile has a boolean variable named selected. When you touch the tile it toogles the variable between true and false. Then if it’s true it changes the tile’s hue to red, if it’s false it sets the hue to white.Hue adds to the objects color, unless the object is white, it wouldn’t flip between white and red, it would add red to the image.

Conditions work like filters, so checking the selected boolean would pick any objects that is set to true or all set to false and the actions would apply to just that object.

You can toggle a boolean or set it directly to true or false.

IDK. I hope this helped and didn’t just add to the confusion. You can combine as many booleans as needed. DoorIsLocked, playerHasKey, then open the door.

1 Like

Hey! I’m finished with my game. I just wanted to say thanks, I had only at least a week to finish without really knowing how gdevelop works, as it was a task given to us by my professor. You’ve been a really big help, I really owe you one. Here’s the link to the game if you’re interested on seeing the final product

1 Like