3
\$\begingroup\$

I'm making a simple 2D, top-view simulation of an evacuation, sprites running around, looking for exits, going at it, all that good stuff.

I have no control over them when the simulation is running, I just program their behaviour.

I'm using the simulation space provided by JADEX, but I'm just using the simplest of what it provides, so it comes down to Java and OOP.

I already have collision detection working, each person has a radius and I search for objects within that radius, so my question is focused on the aftermath.

Say two people collide and one gets pushed to the ground while the other keeps going. No problem so far, but in the cicle after the collision they will again register a collision - since they are still close enough to each other - and trigger a confrontation.

Is there any general or already known technique to deal with this?

Or should I instead focus on another way of detecting a collision?

EDIT:

The expected cases are, when two people collide:

  1. They are both up
  2. One is up (D0) and the other one is down (D1).

In case 2, there are two outcomes:

  1. D0 helps D1
  2. D0 tramples D1

In case 1 there are 3 outcomes:

  1. Both are aggressive. Dices are rolled, one keeps going the other one goes down and his physical condition deteriorates.
  2. Both are non aggressive. Physical condition is compared, winner keeps going, loser is pushed but not to the ground, physical condition does not suffer.
  3. Only one is aggressive. He will always be the winner. Rest as in 1).

As suggested, I will start by having people maintain a list of objects they just collided with and add an extra comparison to that list in the collision detection to filter them and also make sure that when they are no longer colliding to remove them from that list and see how far that takes me.

\$\endgroup\$
2
  • \$\begingroup\$ You should probably say more clearly what the intended outcomes of certain situations are. E.g. two people are colliding: Will always one of the go to the ground, or may they just move apart a bit in the next step? When one collides with one that is on the ground, will trapling on him always be like "no collision" (and can thus be ignored)? When he helps him up, what is preventing him from trampling him down in the next step (and then helping him up again, being stuck in a loop ... (imagine that in reality :-/)). \$\endgroup\$
    – Marco13
    Commented Nov 16, 2015 at 0:34
  • \$\begingroup\$ It sounds like you want to simplify collisions instead of using actual inertia and other physical forces. If that's the case, could you not just make any person who is 'knocked over' become a passive object as far as collisions go? i.e. they start getting smooshed and so can't be smooshing others. \$\endgroup\$
    – user17344
    Commented Nov 16, 2015 at 3:19

1 Answer 1

3
\$\begingroup\$

Usually, (ok, maybe not usually, but at least for ODE (Open Dynamics Engine)) the physics engine does 2 different things:

  1. Detect the collision
  2. React to the collision

And they are done in two distinct phases, and let the user do something in between. The "something" is generally creating a 'contact joint' between the two bodies so that they physically react one to another.

That is, if you want them to react. If you only want to detect that there has been a collision, you don't add a joint, and the solver does not push them around.

So in your situation, what I'd do:

Frame x:

  1. Detect the collision between Dude0 and Dude1.
  2. Is Dude0 or Dude1 having his flag isDownOnTheGround set?
  3. No? Decide who's going down (confrontation) and set the flag isDownOnTheGround for the 'losing Dude'.

Frame x + 1:

  1. Detect the collision between Dude0 and Dude1.
  2. Is Dude0 or Dude1 having his flag isDownOnTheGround set?
  3. Yes? Go on detecting collisions.

Note that another option would be just to remove the 'losing Dude' from the collision detection set.

\$\endgroup\$
6
  • \$\begingroup\$ Frame x is what I'm doing now and I have a 'downed' flag all ready to go, but I would still need to detect downed people in order to trample or help them up. \$\endgroup\$ Commented Nov 15, 2015 at 23:05
  • \$\begingroup\$ @user2993349 Ok, well that's what you do in frame X + 1. Basically, you have to decouple the concepts of "collision detection" from "collision resolution": you detect collision and then you either react to it, in any way you need (resolve collision (push them around), trample them, or help them), or you just skip it (if they're dead or whatever). \$\endgroup\$
    – Vaillancourt
    Commented Nov 15, 2015 at 23:15
  • \$\begingroup\$ I'm having a bit of trouble understanding x+1. If D0 and D1 clash and D1 goes down, D0 needs to go about his life while a possible D2 might decide to trample or help D1. D1 needs to be off D0's equation for a bit, but not D2's. \$\endgroup\$ Commented Nov 15, 2015 at 23:26
  • \$\begingroup\$ @user2993349 Hmm, ok, I think I see your point. Perhaps the "downed" flag is not enough. You could add a set of "ignored dudes" on each dude. This way, at X, if D0 and D1 collide, and D0 'wins', D1 gets his "downed" flag, and D1 is added to the "ignored dudes" set of D0, so that at X+1, if there is a collision detected between D0 and D1, a check is made if D0 must ignore it. This leaves the option for D2 to collide with D1. \$\endgroup\$
    – Vaillancourt
    Commented Nov 15, 2015 at 23:40
  • \$\begingroup\$ I was thinking that, which will however leave me with a restriction that someone can only interact with someone else once. I could maybe only ignore for some time, but since I can't predict exactly what people will do I'm reluctant to add a time sensitive aspect. I might try a combination of time and preventing people from moving inside someone else's radius to allow crowds and avoid too many collisions. \$\endgroup\$ Commented Nov 15, 2015 at 23:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .