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 GarryS

I am having an issue with the following code:

update: function() {
var ball = ig.game.getEntitiesByType(EntityBall);
if (this.touches(ball[0])) {
do stuff
}
}

This code is for a block entity defined in blocks.js. The problem is that it works only some of the time. Specifically, I have 1 EntityBall flying around and 22 EntityBlocks on the board. I use this to test if the ball touches the block and then kill it, etc. It seems that every time I reload the level about 3 or so of the blocks are not affected by the ball touching it. Is there a better way to test for this collision?

1 decade ago by GarryS

I may have a solution:

It seems to work using the checkAgainst and check function instead of checking with touches() in the update function.

	type: ig.Entity.TYPE.B,
	checkAgainst: ig.Entity.TYPE.A,

	check: function ( other ) {
		var ball = ig.game.getEntitiesByType(EntityBall);
        if(this.touches(ball[0])) {
        		this.kill();
        		ball[0].vel.y = ball[0].vel.y * -1;
                console.log('ouch!');
                ig.game.score += ig.game.score;
        }
	},
Page 1 of 1
« first « previous next › last »