Skip to content

Commit

Permalink
Add collision #5
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmedElHanafi committed Mar 17, 2022
1 parent 8626b33 commit b2beaf8
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions js/Sale.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,42 @@ export default class Sale {
var materialBox2 = new BABYLON.StandardMaterial("mat", scene);
var texture2 = new BABYLON.Texture("img/mure.jpg", scene);
materialBox2.diffuseTexture = texture2;

// to be taken into account by collision detection
box1.checkCollisions = true;

box2.material = materialBox2;
box2.position.y= this.oy;
box2.position.x= this.ox;
box2.position.z= this.oz;
// to be taken into account by collision detection
box2.checkCollisions = true;
let boxes = [];
let nb = 0
for (let x = 0; x < this.length; x++) {
for(let z = 0; z < this.width; z++){
if(x==0 || x==this.length-1 || z==0 || z==this.width-1){
if(this.porte[0]<=x && x<=this.porte[2] && this.porte[1]<=z && z<=this.porte[3]){
boxes[nb] = box1.createInstance("copySalebox"+nb);
boxes[nb] = box1.clone();
boxes[nb].position.x += x*this.taille;
boxes[nb].position.z += z*this.taille;
//collision
boxes[nb].checkCollisions = true;
nb+=1;
}else{
for(let y = 0; y < this.height; y++){
boxes[nb] = box2.createInstance("copySalebox"+nb);
boxes[nb].position.x += x*this.taille;
boxes[nb].position.z += z*this.taille;
boxes[nb].position.y += y*this.taille;
boxes[nb].checkCollisions = true;
nb+=1;
}
}
}else{
boxes[nb] = box1.createInstance("copySalebox"+nb);
boxes[nb].position.x += x*this.taille;
boxes[nb].position.z += z*this.taille;
boxes[nb].checkCollisions = true;
nb+=1;
}
}
Expand Down

0 comments on commit b2beaf8

Please sign in to comment.