Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by Ransome

Hi all, got an interesting little bug here. I've got a bunch of blocks I'm trying to stack on top of each other, very simple things really with a vel.y of 100 or so. When I start them above each other they fall and stack fine (their collision is fixed). But when I do a sortEntities() after initializing all of them they fall through each other and then seem to 'pop' into place (in some cases) after they're done.

Also, I tried making them 'ACTIVE' collisions but they all bounced up in the air which I didn't want (even after setting .bounciness=0).

Here's them all stacking properly:

/><br />
<br />
And here's after sortEntities() is called directly after their initialization:<br />
<br />
<img src= this.spawnEntity('EntityBlock',130,250,{blocktype:'small'}); this.spawnEntity('EntityBlock',130,20,{blocktype:'medium'}); this.spawnEntity('EntityBlock',270,250,{blocktype:'medium'}); this.spawnEntity('EntityBlock',270,20,{blocktype:'medium'}); this.spawnEntity('EntityBlock',410,250,{blocktype:'small'}); this.spawnEntity('EntityBlock',410,10,{blocktype:'small'}); this.spawnEntity('EntityBlock',540,140,{blocktype:'medium'}); this.spawnEntity('EntityBlock',540,5,{blocktype:'small'}); this.spawnEntity('EntityBlock',680,350,{blocktype:'large'}); this.spawnEntity('EntityBlock',680,5,{blocktype:'small'}); this.setupMenuBar(); this.sortEntities();
And also sortEntitiesDeferred did the same thing.

1 decade ago by SnakePlissken

Not sure but it may be as easy as doing this instead.

ig.game.sortEntitiesDeferred()

use ig.game instead of this see what happens

1 decade ago by Ransome

Good idea, but it had the same effect as this.sortEntitiesDeferred() :\

1 decade ago by quidmonkey

So is the second picture of the boxes resting or prior to them popping back in place?

1 decade ago by Arantor

The manual notes that FIXED vs FIXED entities do not collide as such.

When are you performing the sortEntities() call?

1 decade ago by Ransome

It's kind of an action shot, how they look as they come down and overlap each other. Here's a video that might explain it better (sorry it's a huge .swf, Jing is the most convenient thing I have to record video quickly and I was in a hurry before work this morning, might need some buffering)

http://www.clumsyfingers.net/misc/badboxes.swf

and here it is with boxes set to ACTIVE collision and with .bounciness set to 0

http://www.clumsyfingers.net/misc/badbouncyboxes.swf

Not sure why they bounce even when bounciness is set to 0. I know FIXED vs FIXED collisions can have undefined results (though I don't know what the correlation with .sortEntities() and .sortEntitiesDeferred() ), so maybe if I can just get them to not change vel when hitting each other with ACTIVE that would be sufficient.

I'm using 1.18 also btw

Edit for Arantor: I call the sortEntities() immediately after spawning all of the entities. I did read that FIXED vs FIXED can be tricky, maybe the ACTIVE bounciness issue is better to resolve?

1 decade ago by quidmonkey

Can you post the code for your EntityBlock class?

1 decade ago by Ransome

Sure, it looks like this:

ig.module(
    'game.entities.gameobjects.block'
)
.requires(
    'impact.entity',
    'game.entities.ui.text',
    'game.entities.gameobjects.pointer'
)
.defines(function() {
    
    EntityBlock = EntityClickable.extend({
    
      size:{x:150,y:118},
      smallBlock: new ig.AnimationSheet('media/maps/1/1/block2.png', 150, 118),
      mediumBlock: new ig.AnimationSheet('media/maps/1/1/block1.png', 150, 176),
      bigBlock: new ig.AnimationSheet('media/maps/1/1/block3.png', 150, 228),
      //collides:ig.Entity.COLLIDES.ACTIVE,
      collides:ig.Entity.COLLIDES.FIXED,
      bounciness:0,
      offset:{x:10,y:0},
      animSheet: this.smallBlock,
      type:ig.Entity.TYPE.B,
      numberText:undefined,
      vel:{x:0,y:100},
      
      init: function(x,y,settings) {
        this.parent(x,y,settings);
        switch(settings.blocktype) {
          case 'small':
            this.animSheet = this.smallBlock;
            this.size = {x:130,y:100};
            break;
          case 'large':
            this.animSheet = this.bigBlock;
            this.size = {x:130,y:200};
            break;
          case 'medium':
          default:
            this.animSheet = this.mediumBlock;
            this.size = {x:130,y:150};
            break;
        }
        this.addAnim('idle',1,[0]);
        this.numberText = ig.game.spawnEntity('EntityText',this.pos.x+40,this.pos.y+50,{
           text:settings.blocktext,
           color:'#000000',
           size:{x:150,y:35},
           font:{size:14,family:"'Engravers','sans-serif'"},
           zIndex:9999999
        });
        
        this.zIndex = (-1*this.pos.x*768)+this.pos.y;
      },
      
      update:function() {
        this.currentAnim = this.anims['idle'];
        this.numberText.pos.x = this.pos.x+40;
        this.numberText.pos.y = this.pos.y+50;
        this.parent();
      }
    
    });

});

1 decade ago by dominic

The FIXED vs. FIXED collision works differently, depending on the order in which entities are checked. That's why it looks fine when it's "unsorted", but breaks after sorting. That's also why FIXED vs. FIXED collision is undefined and should be avoided :)

Use the ACTIVE mode and add some gravity to your game, instead of specifying the velocity for the Boxes themselfs. This will ensure the boxes are in an idle state (standing) when they stack up.

Without gravity or friction, collision works like everything is floating in space. Two cardboard boxes that collide in space will bounce off each other, regardless of their bounciness.

1 decade ago by Ransome

.gravity got it right, thanks dominic :)
Page 1 of 1
« first « previous next › last »