I am making a peggle clone with phaser arcade physics and I’m occasionally seeing some weird physics I cant account for. I have a ball (circular sprite) which gets shot into stationary pegs (circular images).
Best way to explain is this example level I setup for my game. Load the game, hit the “left arrow” twice to aim to the left side of the peg, and hit “space” to shoot. You will see the ball shoot to the left, hit the left side, and then bounce to the right. It should bounce more to the left instead.
// called in the constructor of a Ball.ts class which contains the ball sprite
this.sprite = this.scene.physics.add.sprite(
this.startPoint.x,
this.startPoint.y,
ImageKey.BALL
);
this.sprite.setScale(
this.width / this.sprite.width,
this.width / this.sprite.height
);
this.sprite.body.setCircle(this.width * 2);
this.sprite.setBounce(0.85).setCollideWorldBounds(true);
I have a collision handler here for the ball/peg but I dont think it should end up being a factor:
Changing the bounce to 1 does not change the direction of the bounce at all. Seems like it basically increases the speed it bounces off (and vice-versa for lowering it).
I added a log of separateCircles in my update like this but im not exactly sure what to make of it:
The logs show the overlap amount decreasing as it gets closer to the peg and the result is always true (separation occurred). There is no log where result is false. The overlap increases after it bounces off. The physic behavior is unchanged. Here is the log at it’s lowest overlap value: