Allegro.cc Forums » Programming Questions » How to make a collision box at 360 degrees

 This thread is locked; no one can reply to it.
 How to make a collision box at 360 degrees
 keprast Member #16,794 January 2018 Hello, nice to meet you, no matter who you are.:DI tried to make a 360 degree collision box.But it's not good.It has a strange range of judgment. #SelectExpand 1 bool ppp = false; 2 3 if (box1_x >= box2_x) { 4 px = box1_x - box2_x; 5 } 6 else 7 { 8 px = box2_x - box1_x; 9 } 10 11 if (box1_y >= box2_y) { 12 py = box1_y - box2_y; 13 } 14 else 15 { 16 py = box2_y - box1_y; 17 } 18 19 pz0 = px*px + py*py; 20 pz1 = box1_h*box1_h + box1_w*box1_w; 21 //std::cout << px; 22 23 pz0 = sqrt(pz0); 24 pz1 = sqrt(pz1); 25 //std::cout << pz0 << std::endl; 26 27 if (pz0 <= box1_w || pz0 <= box1_h || pz0 <= box2_w || pz0 <= box2_h|| pz0 <= pz1) { 28 /*collision*/ 29 ppp = true; 30 } 31 else 32 { 33 /*no collision*/ 34 ppp = false; 35 } 36 37 if (ppp) { 38 x -= Vx; 39 y -= Vy;//Incomplete content 40 41 } As you can see, I use the vector distance of two coordinates.And these heights and widths.--------------------------------------------------I have two questions:Except for //Incomplete content.Is it right to do this?If it is wrong, where is it?Please help me.