Collision Trouble

Started by AGP, May 04, 2014, 02:02:12 AM

Previous topic - Next topic

AGP

Here's the problem I'm having with the collision-detection against the ball only working the first couple of times. As the video shows, even when the collision against the ball stops working, the collision against the other players works.

https://dl.dropboxusercontent.com/u/93826015/java%202014-06-28%2004-23-58-66_x264.mp4

EgonOlsen

What exactly are you using for player-ball collisions?

AGP

This:


SimpleVector direction = collideWithBallEllipsoid(new SimpleVector(selectedPlayer.getRoot().getZAxis().x*-.5f, selectedPlayer.getRoot().getZAxis().y*-.5f, selectedPlayer.getRoot().getZAxis().z*-.5f));
ball.direction.add(direction);



     private SimpleVector collideWithBallEllipsoid(SimpleVector playerDirection) {
SimpleVector direction = selectedPlayer.get(0).checkForCollisionEllipsoid(playerDirection, new SimpleVector(1f, 4f, 1f), 3);
if (direction.equals(playerDirection))
     return SimpleVector.ORIGIN;
else if (!direction.equals(playerDirection) && !ball.ball.wasTargetOfLastCollision()) {
     selectedPlayer.collided = true;
     return SimpleVector.ORIGIN;
}
direction.y = 0.00f;
return direction;
     }

EgonOlsen

So the ball gets the correctly player direction assigned to it? If that's the case, what happens to the player then? Ellipsoid collision detection is a collision avoidance algorithm. It can't handle the case that a collision is present already when you call the method. So if it can happen that the player already insects the ball before the call, the results won't be great. To be honest, i wouldn't use this kind of collision detection at all for this kind of problem but some heuristic method based on positions and movement instead.

AGP

OK, thanks, but first things first: isn't it a bug that after a couple of successful collisions the collisions stop working altogether?

When would you use actual collisions? And which type of collision-detection would you prefer?

EgonOlsen

#20
No, i don't think it's a bug. As mentioned, the idea is to correct the translation vector of the colliding object in a way that the collision doesn't happen and the method is actually really stable in providing this. You actually don't use it that way but you apply the translation to the obstacle instead to move it out of the way if i got that right. I think that this might cause the problems that you see, albeit i'm not entirely sure what's going on exactly. It might be the case that the player would actually climb onto the ball but because you apply the translation to the ball instead but without the y component of the translation, the player might move into the ball...or something similar.
However, ellipsoid collision detection is the most tested method in the whole engine and you can be pretty sure that it works the way it's intended to. I know that this sounds stupid, but if it doesn't work then you are either doing it wrong or you are using it in a way in which it's not meant to be used.
About the alternatives...i'm not sure...i would try something based on ball and player position, player direction and radius.

AGP

Egon, I'm in dire need of that World.getScaleInWorldspaceUnits() (or so) method about which we talked. Would you be so kind as to implement it before your next release?

EgonOlsen


EgonOlsen

Please give this jar a try: http://jpct.de/download/beta/jpct.jar

it adds a getBounds() method to World. The parameter allows you to limit the calculation to visible objects only (true) or all (false).

AGP

Awesome. Thanks a lot, pal.

AGP

The first thing that I noticed is that the jar is 5 KB smaller than the previous latest version. And is it possible that it got a little slower?

EgonOlsen

No idea why it's smaller. Might be that i built it in another way the last time. It shouldn't be slower. Performance sometimes slightly changes between versions because of different memory alignment of the code and stuff like that. There's nothing you can do about that.