Trouble with Collision Masks

This topic contains 13 replies, has 3 voices, and was last updated by  CartoonSmart 1 month ago.

  • March 16, 2018 at 12:51 pm #181579

    Hi Justin.

    First, thanks for creating these kits and tutorials.

    I hope there is a simple fix to my question. I’m working up the basic mechanics for a collection game. I set the player in a field of blocks and the physics worked great – couldn’t pass through the blocks. Then I added points to collect scattered among the blocks. I used category, collision, and contact masks for the player and the points. That works great. Now the blocks don’t work – the player can just pass over them. I tried adding a category and collision mask for the blocks but that didn’t help.

    Category masks:
    1 is player
    2 is points
    3 is blocks

    Collision and Connect masks:
    3 for player to collide with
    2 for player to connect with
    1 for point to connect with
    1 for blocks to collide with

    Basing this on the ‘Fly a Ship’ tutorial.

    Any suggestions on using the masks more effectively is greatly appreciated.

  • March 16, 2018 at 1:45 pm #181583

    I think I know the problem. Your Category Makes should always be powers of two. So try…

    Player = 1
    Points = 2
    Blocks = 4

    And so on, 8, 16, 32, 64, 128, 256 …. etc.

    Keep me posted!

  • March 16, 2018 at 3:55 pm #181588

    Thank you for your quick reply.

    It still isn’t working correctly. The player still passes through the blocks. Now have the following config:

    Node . Category . Collision . Contact
    Player 1 . 4 . 2
    Point . 2 . 1 . 1
    Block . 4 . 1 . 1

    I deleted all the blocks and created a new one in case something was hung up in the code. Didn’t help.

    Any further suggestions are greatly appreciated.

    • March 21, 2018 at 8:38 am #181808

      What kind of physics body does the player have? Alpha, Circle, Rectangle?

      Feel free to share some of the code.

    • March 21, 2018 at 1:30 pm #181818

      Using alpha mask for player, bounding rectangle for block.

      Here is the list.plist section related to this
      (player=star, point=block2, block=block)
      Note: block isn’t in code below at this time. I thought it would behave as a physics object because I set it up as such under physics definitions.

      I’m having the same problem on a different page where no masks are defined. set up Star2 as player and kept block for immovable object. Player runs over the block. I don’t know if setting collision masks on one page is impacting another page or if I broke the code somehow.

      The other possibly important factor is that I am using FollowTouch instead of movement control blocks.

      <?xml version=”1.0″ encoding=”UTF-8″?>
      <!DOCTYPE plist PUBLIC “-//Apple//DTD PLIST 1.0//EN” “http://www.apple.com/DTDs/PropertyList-1.0.dtd”>
      <plist version=”1.0″>
      <dict>
      <key>Elements</key>
      <dict>
      <key>Star</key>
      <dict>
      <key>TouchEvent</key>
      <dict>
      <key>StartFollowingTouch</key>
      <string></string>
      </dict>
      </dict>
      <key>Block2</key>
      <dict>
      <key>EventWithContact1</key>
      <dict>
      <key>Remove</key>
      <string></string>
      <key>Increment1</key>
      <string>BlockCount</string>
      </dict>
      </dict>
      </dict>
      <key>EventListeners</key>
      <dict>
      <key>ListenForNewPage</key>
      <dict>
      <key>MeetAllConditionsInGroup</key>
      <true/>
      <key>ListenFor></key>
      <dict>
      <key>BlockCount</key>
      <integer>5</integer>
      </dict>
      <key>ListenForIntersection</key>
      <dict>
      <key>Star</key>
      <string>Portal</string>
      </dict>
      <key>Events</key>
      <dict>
      <key>OpenPage</key>
      <string>Test2</string>
      </dict>
      </dict>
      </dict>
      </dict>
      </plist>

      Thanks for taking the time to look at this.

  • March 21, 2018 at 2:08 am #181799

    Have you checked for both cases in contact? like when BodyA contact with BodyB and BodyB contact with BodyA

    • March 21, 2018 at 1:34 pm #181819

      I believe so. Here is the setup:

      Player(star) is category 1 and can collide with 4 and have contact with 2.
      Points(block2) is category 2 and can collide and have contact with 1.
      Block is category 4 and can collide with 1 and have contact with 0.

      I had originally set Block up to have contact with 1 and it didn’t work. Set it to contact with 0 for some testing reason that didn’t help.

      Thanks for your assistance and I look forward to any insights you may have.

    • March 21, 2018 at 1:37 pm #181820

      Want to just upload the project to your Dropbox or Google Drive and I’ll download it to take a look. You can email me at cartoonsmart@mac.com

    • March 21, 2018 at 1:45 pm #181822

      Done. Thank you.

    • March 21, 2018 at 6:21 pm #181851

      Did you email it? Didn’t see anything yet.

    • March 22, 2018 at 10:20 am #181897

      Sent the link to the Dropbox folder twice. Did you receive it?

  • March 22, 2018 at 11:44 am #181898

    So I’m looking at the Test page, and I changed the Red square (Block) to be Dynamic and Allow Rotation. This allows the star to push around the block.

    What was happening before was the Block was just locked into place. So the star was basically being forced to collide with it because its position is attached to the touch location.

    Its just one of those weird cases where the physics engine has to decide which is the lesser of two evils. The star shouldn’t share the same space as the block, but at the same time, the code keeps telling it to be exactly where your finger is at.

  • March 22, 2018 at 5:51 pm #181918

    Ok. That makes sense. So dynamic will tip the balance to not letting the star run over the block? I’ll play around with it. I wondered if followtouch was triggering the problem. Worst case, I change the interface.

    • March 22, 2018 at 8:30 pm #181919

      Well, the star will then move the block. See if it works for you.

You must be logged in to reply to this topic.

Download the new CartoonSmart TV App - Tons of FREE and Premium Lessons

It's Free Right? Sure, I'll Get It!