Jump to content

Deteção de colisão


JakeBass
 Share

Go to solution Solved by JakeBass,

Recommended Posts

Olá, estou a tentar a fazer um jogo 2D num elemento canvas.

Alguma maneira de detectar interseção entre um path e vários círculos?

se souberem de algum source code que me possa ajudar, ou uma library tb era fixe.

para já tenho isto, mas não tou a perceber como fazer o loop:

var dx = circle1.x - pathX_array;
var dy = circle1.y - pathY_array;
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < radius) {
console.log("success");
}
Edited by apocsantos
geshi
Link to comment
Share on other sites

  • Solution

já me safei, obrigado na mesma... fiz assim:

function check(circle) {
var check = false;
for(var i = 0; i < pathX_array.length; i++) {
var dx = circle.x - pathX_array[i];
var dy = circle.y - pathY_array[i];
var distance = Math.sqrt(dx * dx + dy * dy);
if (distance < 40) {
check = true;
}
}
return check;
}
Edited by apocsantos
geshi
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.