I have two circles. And they can move in any direction. Their movement is based on these values:
circle1.xSpeed & circle1.ySpeed
And the same for the second circle. Now I know when they collide with eachother:
var dx = this.x - other.x;
var dy = this.y - other.y;
var intersectDist = (this.scale + other.scale) - Math.sqrt(dx * dx + dy * dy);
if (intersectDist >= 0) {
// MOVE OBJECTS APART:
intersectDist /= 2;
this.x -= intersectDist * Math.cos(this.dir);
this.y -= intersectDist * Math.sin(this.dir);
other.x -= intersectDist * Math.cos(other.dir);
other.y -= intersectDist * Math.sin(other.dir);
// ADJUST VELOCITY: (STUCK HERE)
}
Im not sure if that is the best way to move the objects apart, but the main issue is the resulting x and y speeds for each object. How can I calculate those?