Group of individual blocks falling with gravity but child rigidbodies not colliding

I’m trying to have Tetris style blocks made up of individual blocks and move and collide them via physics. However I’m having trouble getting things to work properly; how would I get a group of blocks to fall with gravity (while maintaining their shape and grouping) and collide with other groups that will not be falling ?

I currently have the groups falling fine, however I can only get the Collision component on the Entity with the Dynamic Rigidbody on it colliding with the Static Rigidbodies on the non fallen blocks (but that Entity should not collide, only it’s children … hmm).

“Diagram” of my current situation;

  • Block1 (Dynamic Rigidbody, Collision with size 0,0,0)
    – Model (Static Rigidbody, Collision)
    – Model (Static Rigidbody, Collision)
    – Model (Static Rigidbody, Collision)
    – Model (Static Rigidbody, Collision)
  • Block2
    – Model (Static Rigidbody, Collision)
    – Model (Static Rigidbody, Collision)
    – Model (Static Rigidbody, Collision)
    – Model (Static Rigidbody, Collision)


Are you taking about creating compound collision shapes? e.g. multiple collision components forming a single rigidbody? Unfortunately, we don’t currently support compound collision.

Static rigidbodies will not update their position unless “teleported” this.entity.rigidbody.teleport(pos). You could try changing these to kinematic bodies?

They don’t need to form a single rigidbody, they just need to fall as a group, so maybe a single rigidbody is what I needed to do. Basically have a parent that responds to gravity, but have the children keep their local transform and send collision events …

I tried setting the rigidbodies on the models to be Kinematic and no difference, I tried making the falling ones Dynamic (so they fell, but not as a group) and they collided fine. So it seems as though Kinematic/Static rigid bodies can’t collide with each other, is that right ?

If that is the case, is there a way around that, or even making a Dynamic Rigidbody not respond to gravity (as Unity allows) ?

I see, yes, you correct. You cannot collide static and kinematic with each other. (The reason being that these bodies have infinite mass, there is no “defined” collision response if two infinitely massive bodies collide).

You can’t prevent an individual dynamic body from responding to gravity. Though you could either, set scene gravity to 0 and apply gravity to bodies yourself, or apply a opposite gravity force to those you wish to ignore gravity. The first option will probably be more stable.

Hmm. I’ve made gravity 0 and removed the rigidbody and collision from the container and am now looping through the children (the block models) and applying the gravity myself, so they now move and collide fine (although they are not grouped at all, since force is applied to them individually).

Any idea how to stop the blocks from breaking apart ? Am I going to need to manually constrain the transform every frame, or maybe even ditch physics all together and do all the movement and collision detection myself ?

EDIT; I think my next post is the way to go so far …

I’ve now gotten it more or less working by removing the Rigidbodies on the falling blocks, but leaving their Collisions making them Triggers, adding a dynamic Rigidbody to the container to make the block group fall, and then switching the Rigidbodies on the already fallen blocks to Kinematic. This results int he collision style I need, the only issue now is that the triggerenter event (in which I disable the falling Rigidbody) isn’t triggering fast enough, causing the blocks to intersect each other quite a bit before stopping. Any ideas?

I think what you need for this whole thing to work is compound colliders. That way your blocks would automatically be connected and be kept together. Unfortunately playcanvas does not yet support them although it’s in our roadmap to support them.

However you could perhaps try to create compound colliders using ammo directly. If you look here I believe btCompoundShape is what you need.

Before I get into attempting using compound colliders and going around what’s available in PlayCanvas, here is what happens when I place my pieces in a tower and let them fall and collide with each other ( It’s working ok with the setup I mentioned in my last post, aside from the not “instantaneous” collision response.

Any ideas on how to get that to go away? I assume I need to push the body back to compensate for the intersection but I’m not sure where to calculate that (still very new to PlayCanvas).

That might be the best you’ll get as there is presumably one frame of motion before you get the event.

Another way is to use kinematic objects instead of triggers. You can use the “collisionstart” event which gives you more details like contact point.

I think you’ll have the same issue but you will have the contact point if that helps.

Awesome, thanks Dave.

I got it all working perfect now :smile: I changed to using Kinematic Rigidbodies and localPoint.y of the contacts[0] (all 4 contacts had the same values in most, if not every, case) to push it back out and then I snap it to a grid anyway (since the blocks need to perfectly line up). I then had a couple issues with collisions, but they got resolved by simply using the group and mask properties.

1 Like

Great news, are you building this on the site? If so I’d love to see some work in progress :smiley:

It is being built with the editor; however it’s a company project so I’m not sure sharing is allowed. I will however make a point to post a link, crediting your awesome platform and support, to the completed project once it’s up for everyone :smile:

Also, I’ve changed this around somewhat… I have removed the gravity and am now moving my blocks at a constant speed manually. I also realized what contactPoint is, and now feel dumb, and realize why it was always the same. Duh.

I did however completely fix my penetration issues by using results.other (which is the block that the falling shapes collide with), get it’s position and then figure out which of the blocks in the falling shape hit it and get it’s position, then find offset the entire shape by however much it takes to move the colliding block out of the other. Works great now, even with sped up dropping (which caused a lot of penetration issues before).