Help with cube picking logic

0 favourites
  • 6 posts
From the Asset Store
100 items casual and logic games. All icons are of a high quality.
  • Hi, I'm having problems with cube picking logic in my game.

    PROBLEM 1: My platform player character can pick up (and put down) cubes and this is somewhat working, however I'm having some placement issues when multiple cubes are stacked on top of each other. I'm spawning a checker sprite to look for overlap with cubes to pick the right one from the stack and this seems to work. However, when I move and pin the picked sprite to the player object, all the cubes above the picked one in the stack are moved around as well. I'm pretty sure this has a simple solution I'm not realizing, but I'm having a hard time figuring out the issue and none of my attempts to fix it have been successful.

    PROBLEM 2: This is a lesser issue but still concerning, if PushOutSolid behavior is set to active on the player object, all the cubes and player freeze on level startup and are unable to move (even though player object isn't overlapping any solid). I have no idea what causes this and would like to find the issue and fix it, as this might cause problems later on.

    Here's the C3 file with both problems showcased and explained on their own layouts:

    drive.google.com/file/d/1PMmiP1z9dRThKaHKMTIDTT3_g58ib0ic/view

    This is currently a pretty big blocker for my game, so if anyone has time to look into this, help is very much appreciated! Thanks!

  • Instead of moving it, I destroyed and created another, it worked.

    Hope it helps

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hi dupuqub , thank you very much for looking into this! I tested destroying and spawning a new cube instead of moving the existing one and it does indeed work, but the cubes in my game have quite a lot of variables with set values that need to be carried over, so I would ideally like to just reposition the existing cube to keep everything working (without adding extra events for setting the values again for the new cube).

    I'd also like to find the cause of the issue and fix it instead of working around it, to both learn and avoid similar problems in the future. However, if I'm unable to find another solution, I will probably do what you suggested and use the destroy and respawn method, even if it means some extra events in my code to keep the cube values/settings. Thanks again for your help!:)

  • Ok, I had a deeper look in the code, but I had a lot of trouble following what was going on, so I tried to strip everything to the bare minimum.

    I made this version with a somewhat decent solution. I know it's not the droid you were looking for, but maybe there's some process here that's helpful.

    Concerning finding the error in your original code, while stripping everything, it came to mind that after you disable Platform and Solid, you should wait 0.1 or even 0.01 before moving the cube, so the engine can have a tick to compute the behavior change.

    I don't know if this is the real fix for the original code, but it is quite possibly it.

    drive.google.com/file/d/1g6BgxU0rej4YTsfpOFCy7St_l0aZaoBg/view

    EDIT: I'm also not using the "Push Out Solid" addon, the behavior "Custom" has the action "Push out solid" that fixes the edge case where you place a cube above you and then you get trapped inside it.

  • Huge thanks for taking time to help out with this dupuqub ! I will take a better look on the project file later today when I'm back at my desk, but on a quick glimpse this looks like a simple yet effective method for the picking and seems to solve the issues I was previously having. I will definitely test this method further with my game and see if it works in the grand scheme of things, but I'm hopeful it will. Thanks again!:)

  • hahah just realized theres a tiny game going on in my example, theres a way to stack the boxes so you can climb out of the walls lol

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