wexing Posted January 15, 2018 Share Posted January 15, 2018 Hi, i have the problem that body overflows another static body on first collision(gif file attached). Maybe somebody knows some solution? Thank you. Code: this.physics.startSystem(Phaser.Physics.P2JS); this.physics.p2.restitution = 0.63; this.physics.p2.gravity.y = 3000; this.physics.p2.gravity.x = 0; this.ballCollisionGroup = this.game.physics.p2.createCollisionGroup(); this.hoopCollisionGroup = this.game.physics.p2.createCollisionGroup(); this.groundCollisionGroup = this.game.physics.p2.createCollisionGroup(); this.ball = this.game.add.sprite(-120, 500,'ball'); this.game.physics.p2.enable(this.ball); this.ball.body.setCircle(23); this.ball.body.setCollisionGroup(this.ballCollisionGroup); this.ball.body.collides([this.hoopCollisionGroup, this.groundCollisionGroup]); this.ball.body.debug = true; this.hoop_left = this.game.add.sprite(565, 294,'rect'); this.game.physics.p2.enable(this.hoop_left); this.hoop_left.body.setRectangle(5,10); this.hoop_left.body.static = true; this.hoop_left.body.setCollisionGroup(this.hoopCollisionGroup); this.hoop_left.body.collides([this.ballCollisionGroup]); this.hoop_left.original_key = 'hoop_left'; this.hoop_left.body.debug = true; this.hoop_right = this.game.add.sprite(619, 294, 'rect'); this.game.physics.p2.enable(this.hoop_right); this.hoop_right.body.setRectangle(5,10); this.hoop_right.body.static = true; this.hoop_right.body.setCollisionGroup(this.hoopCollisionGroup); this.hoop_right.body.collides([this.ballCollisionGroup]); this.hoop_right.original_key = 'hoop_right'; this.hoop_right.body.debug = true; this.ball.body.velocity.x = 932; this.ball.body.velocity.y = -1536; this.ball.body.rotateLeft(300); Link to comment Share on other sites More sharing options...
gauravD Posted January 15, 2018 Share Posted January 15, 2018 Hi wexing. What do you mean by overflow? The ball slightly entering the right_hoop ? This might be due to tunnelling. Quote In a discrete dynamics world, (i.e. when not using Continuous Collision Detection), objects are moved to a new place each tick, and then collision tests are performed. This means that the object, if fast enough, can move from one side of a wall to another without any collision being registered. This is called tunnelling and is usually a bug. It can be fixed by using Continuous Collision Detection or by Stepping the World at a faster internal rate. AFAIK, p2js only partially supports Continuous Collision Detection, if at all. Making the hoop rects slightly wider, will help - https://jsfiddle.net/gauravdixitv/cb0z6yb7/ wexing 1 Link to comment Share on other sites More sharing options...
wexing Posted January 15, 2018 Author Share Posted January 15, 2018 Yeah, ball slightly entering the right_hoop. I have changed gravity y to 2000 and thats solved my problem. Link to comment Share on other sites More sharing options...
Recommended Posts