Estoy tratando de encontrar el error que da la dirección opuesta a la bola cuando una bola blanca la golpea desde el borde. Por ejemplo, cuando una bola blanca golpea desde el Grom de la bola por el lado derecho, debería ir hacia la izquierda, pero también hacia la derecha. ¿Por que es esto entonces? Sucede si lo golpeas a alta velocidad y cuando realmente apuntas al borde.
Aquí hay un código del juego:
private resolveBallsCollision(primero: Bola, segundo: Bola): booleano {
if (!first.visible || !second.visible) { return false; } // Find a normal vector const n: Vector2 = first.position.subtract(second.position); // Find distance const dist: number = n.length; if (dist > ballConfig.diameter) { return false; } // Find minimum translation distance const mtd = n.mult((ballConfig.diameter - dist) / dist); // Push-pull balls apart first.position = first.position.add(mtd.mult(0.5)); second.position = second.position.subtract(mtd.mult(0.5)); // Find unit normal vector const un = n.mult(1 / n.length); // Find unit tangent vector const ut = new Vector2(-un.y, un.x); // Project velocities onto the unit normal and unit tangent vectors const v1n: number = un.dot(first.velocity); const v1t: number = ut.dot(first.velocity); const v2n: number = un.dot(second.velocity); const v2t: number = ut.dot(second.velocity); // Convert the scalar normal and tangential velocities into vectors const v1nTag: Vector2 = un.mult(v2n); const v1tTag: Vector2 = ut.mult(v1t); const v2nTag: Vector2 = un.mult(v1n); const v2tTag: Vector2 = ut.mult(v2t); // Update velocities (summ velocities from hit & rotation) first.velocity = v1nTag.add(v1tTag); second.velocity = v2nTag.add(v2tTag); first.velocity = first.velocity.mult(1 - physicsConfig.collisionLoss); second.velocity = second.velocity.mult(1 - physicsConfig.collisionLoss); // Update rotations first.rotation = { x: 0, y: 0, z: 0 } second.rotation = { x: 0, y: 0, z: 0 } return true; }