Javascript - Circle-Circle Collision Issue
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am making a game in HTML5, Canvas, and this is my code for resolving collision between two moving circles: function resCCCol(a, b) { var dx = a.x - b.x; var dy = a.y - b.y; var dist = dx * dx + dy * dy; var vx = b.vx - a.vx; var vy = b.vy - a.vy; var dot = dx * vx + dy * vy; if (dot > 0) { var scale = dot / dist; var cx = dx * scale; var cy = dy * scale; var mass = a.r + b.r; var cw1 = 2 * b.r / mass; var cw2 = 2 * a.r / mass; a.vx += cw1 * cx a.vy += cw1 * cy b.vx -= cw2 * cx b.vy -= cw2 * cy } } If I set the coordinates so that the