How do I define the navigation of two objects according to the proximity of the destination?

0 favourites
From the Asset Store
This is a Dungeon Master tool & the 1st of 12 Combat Engines from the Building Combat Engines for Browser Games workshop
  • I have a problem creating mechanics for a game.

    In the attached file, you need to click on the buttons to move the colored objects, according to their proximity, always giving preference to the blue one. Whenever you click a button, the system has to identify which of the two objects is closest to it and send it to the base closest to that button. It started working well but then it stopped moving the objects and sometimes sent the object to a completely different path.

    I did it another way, but the code was too long and I'm trying to cut it down.

    Could anyone help me solve this mechanic?

    Thanks in advance

    we.tl/t-vtycEuQAxF

    EDITED: Objective of the game: move the objects, removing the red ones in front of the blue one (there will be many scattered across the screen) until the blue one reaches the end. There is a movement limi, but I just want to solve the mechanics.

  • First, you need to move "Base is not occupied" condition above "Pick nearest". But that won't fix the problem completely, because the nearest base will not always be the correct one. For example here the nearest unoccupied base for blue sprite is the one with the green circle:

    You need to pick only the bases which are connected to this button. You can use the Path sprite if you extend it slightly so that it overlaps Base sprites.

    Button is overlapping Path
    Path is overlapping Base
    Base is NOT occupied
    Pick nearest Base
    

    Or you can give unique IDs to each base and specify on the button which bases it's connected to.

  • Hi dop2000

    Thanks. I will implement your first suggestion, because the paths are really overlapping the bases. So I don't need to use "Pick all" first?

    EDITED: I included the conditions and fixed the order, and it is indeed moving to the nearest base, however, they do not return to the previous base when I click the same button.

    Or you can give unique IDs to each base and specify on the button which bases it's connected to.

    Maybe this is the solution, but how do you specify which bases are connected to the buttons in the code?

  • however, they do not return to the previous base when I click the same button.

    Maybe you are not clearing the occupied status of the base?

    Maybe this is the solution, but how do you specify which bases are connected to the buttons in the code?

    There are several ways. Since every button is connected to one or two bases, you can define two instance variables: connectionA, connectionB. Manually configure them for every button. When a button is clicked, pick bases with ID=Button.connectionA or ID=Button.connectionB

    But the solution with the overlapping paths is probably easier.

  • Thanks for answering dop2000

    Maybe you are not clearing the occupied status of the base?

    I'm enabling the "occupied" boolean when the object is overlapping the base and disabled when it stops overlapping. Would there be a more efficient way to do this?

    But the solution with the overlapping paths is probably easier.

    The "overlapping paths" suggestion is easier but is not working properly, as I showed in the last image. I'm going to do some tests to see if this other way (using variables to connect to the button) will work.

    EDITED: we.tl/t-mzKJL5jlsj

    Just for you to check if this is the idea.

  • You can run the game in debug mode and check if the occupied variable is set correctly.

  • In fact, I already changed the code to check the bases connected to each button, but something is wrong and the objects no longer move. I'll wait to see if anyone could check the file to see what I might be doing wrong. But thans anyway.

  • I changed the arrangement of the conditionals and now it's working, however, I'm really having trouble leaving the bases free (not occupied). "Overlapping" checks all the time whether or not one object is overlapping another? Because if so, how do I check that it is not overlapping, it should change the boolean.

    we.tl/t-wLNGpSBa5w

  • In the end, none of the options discussed here worked properly. Some conflicts exist because bases can be related to more than one button (per control option)/path (per "overlay" option). I'm stuck on this and I would really appreciate it if anyone else suggested a viable solution to this type of mechanic. Thanks.

  • Any help please?

  • There are two problems with events 9-12 in your project: they run on every tick, and they don't update unoccupied bases. That's why I suggested using debug mode - you could've spotted this sooner.

    When you have "PS Overlapping Base ... Else ...", "Else" condition in this case doesn't mean "all instances that are not overlapping". It means "if the previous condition did not pick anything". So as long as PS is overlapping at least one base, the Else condition won't work.

    Ideally you need to update bases once only after the object has arrived.

    You also need to pick the right PS instance. Picking the nearest is not always correct. When a button is clicked, pick the bases connected to it, and then pick PS instance overlapping these bases.

  • Thanks for sending me a better thought out solution. Using the function in this case is much more effective. I also didn't know that it would be better to distribute the conditions between events instead of combining everything in one event.

    However, the same error still persists as in the previous solution. I am sending the screens below as an example:

    If I click on the button to the right of the initial blue one and then on the button that is diagonally, the blue object crosses the area without a path.

    To lower the red object to the next base, I can either click on the button that appears just below or on the other button that is to the right of the destination base.

    If I click on the button that is to the left of the target button, the object moves diagonally to the base that is on the far left

  • I thought about defining a distance to prevent a button further away from activating the object's movement, but then another problem arises, which is that some paths may be longer, as in the case of diagonal paths, for example. Would there be a solution for this?

    Perhaps I could control the value of this distance through a global variable and that you define by a value of a variable on the buttons themselves and then delete the value of the global variable when the object arrived at the base.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I noticed that some buttons were incorrectly configured in your project - check all IDs and connections.

    Also, like I said, when a button is pressed, you need to pick the valid PS instance, which is on a base connected to the button. Not sure if picking by distance will always work.

    If there are other problems, I highly recommend using Debug View and console logging for troubleshooting.

  • "Distance" didn't solve the problem, because when I have a very long path and have to assign a high distance, this ends up interfering with other bases.

    I had already fixed the problem with some IDs. Everything is right. I believe your file has the same problem as mine, which is that other buttons that also control the same base can move objects that are far from them.

    I am sharing my file with this problem. Could you share yours so I can check?

    we.tl/t-sfk2nTcwlH

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