I am working on a breakout clone which has destructible blocks that can speed up your ball. Afaik, the only way to change the speed of an object is this (I am using arcade physics):
const velX = Math.cos(angle) * newSpeed const velY = Math.sin(angle) * newSpeed this.body.setVelocity(velX, velY)
Now here is the problem. I have to execute this code in the collision callback between the ball and the block. This callback fires before the ball has changed direction due to the collision. If I query the current angle of the body’s velocity vector like this:
const angle = this.body.angle
It will give me the angle before the collision, meaning my call to setVelocity will cause the ball to maintain the direction it had before the collision. The ball will effectively speed right through the block it destroys instead of bouncing off.
Is there any way to change the speed of an object without specifying a direction?
OR is there any way to query the object’s angle after the collision, so I can use setVelocity?
OR is there any other way to achieve this behavior?
Any help is much appreciated!