How do i make my game's basic mechanics: drag, click, put on shelf

0 favourites
  • 6 posts
From the Asset Store
Click! Click! 136 click sounds for your video games or media projects
  • Really need help, I'm making my first big game in construct 3. I apologize for my bad English.

    I have a few problems, I will try to explain them:

    1. I need to implement in the children's game drag and drop objects so that in the floor collision area they can be dragged from place to place, and when they are lifted to the wall level and released they fall on the upper boundary of the floor collision or on another solid object (shelves, dresser and so on). That is, I have one large background sprite that shows the wall and the floor, and the collision is the floor. I added all the dragable objects to the “DragItems” family, and the “solid” objects to the “DropSolid” family. I tried experimenting with physics and turned it on exactly at the moment of falling, because I need the effect of a slight bounce at the moment of contact with a solid surface. But so far, the drag works on the entire surface of the sprite, without taking collision into account.

    2. Problem #2.

    I have static objects that are clickable (on/off lamp light for example or open/close curtain) and draggable objects that have clickable actions (also on/off screen or on/off particle creation). But so far I don't have a distinction between click and drag, is there any way to distinguish between them? That is, if I have a click interaction on an object, then dragging it would not trigger a conditional click? Also when dragging an object or clicking on a static object they can be triggered simultaneously, i.e. clicked. This happens with interface elements, if I click on the button, which is above some interactive clickable object, they both work! It really interferes with my game and I would like to fix it, how to remove this particular clicking?

    3. Problem #3.

    I need to implement the ability to put objects on shelves, in a cabinet, in a box. Boxes can be interactive, that is, if it is closed, then the objects in it are hidden and dragged together with it, if you drag the box open, then the objects should be visible on the half, as if sticking out of it. If stacked in a closet, they can be covered by a door, or overlapped by the top of a shelf. It is also necessary that when an object is lifted above the bottom of the shelf, then it falls on the shelf. If you stack two similar objects on top of each other, they should become on top of each other without overlapping. And also limit the size, that is, if the object is taller or wider than the size of the shelf or box, you can't stack it there anymore. I tried to implement it by my own efforts, having read the whole forum and other tutorials, it works, but with errors.

    My project is already too big, so I made a mini-copy to demonstrate all these problems. I apologize if I attached and posted wrong, this is my first time posting on the forum and sharing my project. I have already done a lot of things, but I can't overcome the most important mechanics of my game, I really believe in the power of the forum and need help! Thank you in advance for your help!

    https://www.dropbox.com/scl/fi/rzymzqaf93v653xvgfkk9/C3_problem.c3p?rlkey=e830m0v8xvvvvboll6bnh13wz&st=5kyrycq6&dl=0

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 1. DragAndDrop behavior ignores Solid. Physics is also not compatible with Solid.

    If you need physics object to collide with other physics objects while dragging, you need to move them with physics actions - apply force, velocity etc.

    Check out these examples:

    howtoconstructdemos.com/physics-puzzler-move-and-re-arrange-blocks-with-mouse-c3p

    howtoconstructdemos.com/physics-game-catch-apples-with-a-bucket-capx

    2. You can use Touch plugin, it has "On Object Tap" condition - it's a gesture which only triggers if the object is quickly touched/clicked without moving.

    Alternatively you can save the time and position of the click, and when the mouse button is released compare how much time has passed from the start of the click, and how far the object was moved. Say, if the time<0.3s and the distance<5px, then toggle the switch.

    3. This task may be pretty difficult. When the cabinet is closed, you can disable physics for all objects inside of it, and add them as children to the cabinet (using hierarchy). Then they will be moved with the parent.

    To arrange objects on shelves you probably need to define which objects can collide, using "Enable/Disable collisions" action.

  • Thank you so much for your detailed response!

    I have very little experience in development on Construct 3, so any help is very important for me. By the way, when I was looking for a solution on my own, your answers under other posts were very useful for me and helped me to solve other problems!

    I will definitely look at the attached examples and try to apply them in my project, as for the first problem.

    Alternatively you can save the time and position of the click, and when the mouse button is released compare how much time has passed from the start of the click, and how far the object was moved. Say, if the time<0.3s and the distance<5px, then toggle the switch.

    I tried to cope with the second one, but I already have a lot of things tied to the mouse in my project, I thought to do everything with it, and for the mobile version to enable the touch simulator, which is in the settings. So if I want to remove “clicking” through two different clickable objects, I need to add what you suggested to each condition? I don't quite understand how to implement it, but I'll try! It would be great if there is a similar example of implementation, because I looked at the information on the forum, but there are more often found narrow examples that I do not understand how to apply in my project.

    As for the third problem, I'll take it into account, thanks! But it is not clear how to limit the zone of the box, for example, so that the object does not go beyond its limits. Forgotten still enclose skrinchot event to realize box that works but not always accurate.

  • Here is the solution to #2

    dropbox.com/scl/fi/j6vtjlirv55gojr4b0gci/DragAndToggle.c3p

    Like I said, #3 may be difficult. Perhaps you need to use invisible immovable sprites to limit the zone of the box. Or you can allow the object to go through the walls while dragging, but when released snap it to the nearest free shelf.

  • Here is the solution to #2

    dropbox.com/scl/fi/j6vtjlirv55gojr4b0gci/DragAndToggle.c3p

    Wow, that's just genius! I had to do a bit of work and rearrange the project to build this solution in, but it works just perfectly, thank you so much!

    By the way, maybe you also know how to remove click-through if two interactive objects are overlapping and the interaction should be only with the top one? I roughly logically understand how it should look like and read on the forum about “Pick Top Instance”, but I don't quite understand how it can be realized, as there are clickable draggable objects, there is an interface and there are static but clickable objects. It turns out in the condition to each interactive object to the action “on object clicked” add the condition of the top object? Isn't there a more simplified system, since there are many objects and not all of them are in families?

    Found a recent post with a similar problem, tried to apply the solution but it doesn't work: construct.net/en/forum/construct-3/how-do-i-8/stop-mouse-click-effecting-183983

    I really appreciate your help, you are my savior!

  • When several objects are draggable/clickable you can use "Pick top instance".

    There are many way to prevent click-through - one solution is to disable/enable layer interactivity. For example, when menu layer is active, disable interactivity on all game layers. Another option is to organize events in groups and activate/deactivate them. Say, if an object is clicked, deactivate "UI controls" group.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)