0 Favourites

Checking for two collisions at once on one object

  • I'm having an issue that I can't quite figure out, so any insight would be greatly appreciated:

    I have a fork shaped object with two equal length prongs. The collision mask is shaped in a way that fits over both prongs. When a key is pressed, the fork object moves forward and collides with two separate blocks (one in front of each prong).

    My collision event looks roughly like this:

    Fork: On Collision with Block >
    Set Block X to Self.X + 50
    Set Fork 'returning' to 'True' (which makes the object go backwards)[/code:p5zn5j2o]
    
    Originally, I anticipated that the fork would push both blocks in this setup. However, it seems that the fork will only push one of the blocks, as though it's hitting that one "first" and retreating before the event can run for the second block.
    
    How can I make the stick push both blocks at once? Hopefully my example is clear enough to address; I would include a .capx but I'm away from my home computer.
    
    Thanks in advance!
  • Add a For each block when checking for collision...

  • Like this?

    Fork: On Collision with Block
    System: For each Block: Set Block X to Self.X + 50
    [blank]: Set Fork 'returning' to 'True' (which makes the object go backwards)
    [/code:2q7eopcp]
    
    That doesn't change anything. It still only pushes one block.
  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Share a capx so we can take a look at it, then...

  • noisetank

    Check the collision box X values on each tine to make sure they are identical (set them to whole numbers). If you have Pixel Rounding set to OFF, and the values are fractionally different, the fork may not collide correctly.

    EDIT: This goes for the two boxes as well.

    Here's a capx:

    https://dl.dropboxusercontent.com/u/12667027/ForkTest.capx

  • noisetank

    Check the collision box X values on each tine to make sure they are identical (set them to whole numbers). If you have Pixel Rounding set to OFF, and the values are fractionally different, the fork may not collide correctly.

    EDIT: This goes for the two boxes as well.

    Here's a capx:

    https://dl.dropboxusercontent.com/u/12667027/ForkTest.capx

    Good advice! This wasn't the solution, but that fact about pixel rounding was new to me and your capx was helpful in showing that the issue is definitely specific to my events.

    It turns out that my "returning" boolean was getting switched on too quickly, so the second collision wouldn't occur. Adding a small delay (Wait 0.05 seconds) seems to have fixed that, although it's kind of annoying to see the second block lag after the first. I can probably do some tinkering to try and eliminate that, though.

    Thank you for the help!

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