# How to deal with collision detection result

I have a render loop. In it I always call the update() method which moves all the objects in their own directions. Then after that I call checkCollision on each object with each object like that:

for (GameBodyObject gbo1 : objects) {
for(GameBodyObject gbo2 : objects) {
if(!gbo1.equals(gbo2)) {
gbo1.checkCollision(gbo2);
}
}
}


btw I am using Circle as collider

now in checkCollision I first check if they collide and then if yes I calculate the displacement like this:

if(CircleCollider.collide(p1, r1, p2, r2)) {
double totalR = r1 + r2;
double a = new Vector(p1.getX() - p2.getX(), p1.getY() - p2.getY()).getAngle();

double intersection = Math.abs(totalR - p1.distance(p2));

return new Vector(Math.cos(a) * intersection, Math.sin(a) * intersection);
} else {
return new Vector(0, 0);
}


then I move the GameBodyObject by this displacement vector like this:

public Point moveByVector(Vector v) {
if(v.getX() == 0 && v.getY() == 0) {
return this;
}
double a = v.getAngle();
double l = v.getLength();
x += l * Math.cos(a);
y += l * Math.sin(a);
return this;
}


However I get a bouncing effect so the one gameBodyObject goes into another gameBodyObject and back and again into that gameBodyObject and back. I want it to stop, not to bounce.

How could I do that?

One way that come up to my mind is that I will check for collision in the update() function directly and if it occurs I won't move the guy, but then it may get stuck if he runs into another gameBodyObject...

How should I deal with that?

(BTW did you play Dota 2? I want the mechanics similar to that game so that one player can block another player and trees are static so they don't move so the player can't push them instead he stops...)

• Dota almost guaranteed doesn't use any sort of physics engine to handle collisions. It's probably all done tile-by-tile / navmesh during the broadphase and very simple bounding boxes / ellipses during the narrow-phase. How they handle collisions is by not handling collisions at all except for setting a flag that you cannot move in that direction. – Charanor Jul 31 '17 at 1:33
• That's interesting, let me try to apply that – durisvk10 Jul 31 '17 at 12:39
• Btw I don't know what tile-by-tile and navmesh means. To me Dota 2 engine and the physics is based on Warcraft III from which the Dota originally come from and there it looks like they are also using circle collider (because if you select unit you see the circle under it and if you watch carefully the two circles never intersects) @Charanor – durisvk10 Jul 31 '17 at 13:38