Navigation

    CreatiCode Scratch Forum

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • CreatiCode

    Dominance Group in 2D Physics

    2D Blocks
    1
    1
    226
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • info-creaticode
      CreatiCode last edited by admin

      Introduction

      After 2 objects collide, the 2D physics engine calculates where they would go based on their physics properties, such as mass, speed and restitution. In general, the object with a faster speed or larger mass would tend to “dominate” the interaction, pushing the other object away while maintaining its own course. However, we can change that using “dominance group”.

       

      Set Dominance Group

      We can set the dominance group of any sprite using this block:

      48ae38e1-2cf2-4ccc-832f-3f0c3a381802-image.png

       
      The new group number can be any value between -127 and 127. By default, every object has a dominance group of 0.

      When two or more objects interact with each other, the object with a higher dominance group will have a “stronger weight” on the result. For example, if 2 objects collide, then the one with a higher dominance group would maintain its course, while the other object will be bounced away.

       
       

      Demo

      In this demo project, there are 2 sprites, one beach ball and one basketball. When these 2 balls collide, and if their dominance groups are both 0, then both of them bounce back:

      b1.gif

       
      However, when we set the dominance group of the beach ball to 1, it will not bounce back:

      b2.gif

       
      You can play with this project or modify it here:

      https://play.creaticode.com/projects/65144b7b78dfe33adbb6e2d8

      1 Reply Last reply Reply Quote 0
      • First post
        Last post