Have Object Detect If Completely Inside Other Object Javascript
Hello I'm making a game for my CS class using JavaScript. I know how to ale objects collide with each other in the canvas but I m trying to get an object to detect if it's complete
Solution 1:
//both height and width need to be smaller than the containing objects height
//and width.
if(obect1.width < object2.width && object1.height < object2.height){
//check if right side x of object1 is less than right side x of object2
//and check if bottom y of object1 y is less than bottom y of object2
//and check if left x of object1 is greater than left side x of object2
//and check if top y of object1 is greater than top y of object2
if(object1.x+object1.width < object2.x+object2.width
&& object1.y+object1.height < object2.y + object2.height
&& object1.x > object2.x && object1.y > object2.y){
return True;
}
}
return False;
Post a Comment for "Have Object Detect If Completely Inside Other Object Javascript"