Skip to content

Update index.html #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

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