Skip to content

Conversation

@jainish2222
Copy link

Prevent ball from getting stuck on obstacles in Plinko game

@jainish2222
Copy link
Author

i have solution for this // Check collision with a peg
for (let peg of pegs) {
const dx = ball.x - peg.x;
const dy = ball.y - peg.y;
const distance = Math.sqrt(dx * dx + dy * dy);
const minDistance = ball.radius + peg.radius;

if (distance < minDistance) {
// Collision detected

// Add a small random horizontal push to prevent sticking
const angle = Math.atan2(dy, dx);
const push = 0.5 + Math.random() * 0.5; // push between 0.5 and 1.0
ball.vx += Math.cos(angle) * push;
ball.vy += Math.sin(angle) * push;

}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant