Collision detection problem

Started by ndr123, November 08, 2011, 06:04:57 PM

Previous topic - Next topic

ndr123

Hi,
I'm having a problem with collision detection. If I use checkforcollisionellipsoid, collisions are detected and everything works fine. The problem is when I try to use checkforcollisiospherical. When I do, collisions aren't detected and so nothing works anymore.
In particular, I have some spheres with radius 1 created by copying them from a sphere created through Primitives.getSphere(12, 1). I tried using checkforcollisionspherical as now I'm calling the checkforcollisionellipsoid with new SimpleVector(1.2, 1.2, 1.2) as ellipsoid and so I though I could save time using the faster checkforcollisionspherical (through what I read, I understood checkforcollisionspherical is faster than checkforcollisionellipsoid).

EgonOlsen

It is faster, but actually not that much. In your case, it's difficult to tell without knowing more about the specific scene. Spherical collision detection isn't a swept approach, i.e. it's possible to "jump over" obstacles if the translation is quite long compared to the collision objects. If , for example, you translate by 5,0,0 and at 2.5,0,0 there's a sphere of radius 1, this won't be detected. Might that cause the problem? Anyway, if it isn't a huge performance problem, i would stay with what works for you. Ellipsoid collision detection is simply more powerful, sliding is better etc. So prefer it if possible even if it's a tad slower.

ndr123

No, it is not the problem as the maximum translation is (1,1,1) but usually it is enough smaller (I create the components of the translation vector through Math.random() ).

EgonOlsen

In my test case, that collision method works just fine. If it doesn't work for you and you really have/want to use it, i need some test case to verify this problem.

ndr123

Maybe it is something related to the fact that I create the spheres through copyObject() from an initial one cause I remember I tried to use the spherical collision when I used to create all the spheres through Primitives.getSphere and it worked at that time.

EgonOlsen

As long as you set the collision mode correctly on the copy, i don't see how this should affect collision detection... ???

EgonOlsen

I've just checked my test case again. It also uses cloned sphere objects and it runs just fine with spherical collision detection...

ndr123

#7
I set collision mode correctly as the only thing I change while changing to ellipsoid to spherical is the checkforcollision call. And that's why I can't understand which the problem is.
This is how I create the spheres

for(int i = 0; i < NR_SPHERES_LV5; i++){
sphere_velocity[i] = new SimpleVector(Math.random()*MAX_VELOCITY, Math.random()*MAX_VELOCITY,Math.random()*MAX_VELOCITY);
sphere_initial_position[i] = new SimpleVector((Math.random()*(CARTESIAN_WIDTH-3))-((CARTESIAN_WIDTH-3)/2),
(Math.random()*(CARTESIAN_HEIGHT-3))-((CARTESIAN_HEIGHT-3)/2),
(Math.random()*(CARTESIAN_DEPTH-3))+1.5);
sphere_exploded[i] = false;
sphere_explosion_time[i] = 0;
sphere_explosion_scale[i] = 1;
chain_explosion_nr[i] = -1;
spheres[i] = base_sphere.cloneObject();
spheres[i].setTexture(sphere_textures[color_index]);
spheres[i].setCollisionMode(Object3D.COLLISION_CHECK_SELF);
color_index++;
if(color_index == sphere_textures.length)
color_index = 0;
}

and this is how now I check for collisions:
v = spheres[i].checkForCollisionEllipsoid(sphere_velocity[i], ellipsoid, 3);
sphere_velocity is a vector containing the translation vector of each sphere and ellipsoid = new SimpleVector(1.2, 1.2, 1.2).
When I tried using the checkforcollisionspherical I called it with various radius but with no one I got collision.

EgonOlsen

That's the call for ellipsoid collision detection. Can you post the one for spherical in addition?

ndr123


v = spheres[i].checkForCollisionSpherical(sphere_velocity[i], 1);

I tried also with other radius (e.g. 5, 10) but collisions weren't detected too.

EgonOlsen

No idea then...what puzzles me, is the collision mode that you set for the spheres. It seems wrong to me and i would expect it to be


spheres[i].setCollisionMode(Object3D.COLLISION_CHECK_SELF || Object3D.COLLISION_CHECK_OTHERS);


if each sphere should be able to collide with all the others. However, this should prevent ellipsoid collision detection from working too. Maybe you change that part and try again? If it works then, something is wrong with these modes when using ellipsoid.

ndr123

No the collision mode is correct as spheres should not collide with all the others. At this first stage, they should collide only with walls to remain inside the screen but they don't and go out of the screen.
To make more clear, I'm deleveloping a game in which you have spheres running around in a 3D room; they not collide with each other but just with walls. Then by touching the screen, you shoot a sphere and by touching again you make it explode. After the explosion, if a sphere collides with the exploded sphere, it explodes too (when a sphere explodes, it stops moving and grows a little and I change its collision mode from check self to check others) and the goal is to make explode as much spheres as possible.

EgonOlsen

Have you tried to adjust Config.collideOffset?

ndr123

Yes usually I have it set to 5 but I changed it to more than 100 during my tests (I don't remember the exact number)

EgonOlsen

5 is a little too small IMHO...however, if 100 doesn't help either, then i'm out of ideas. I need a test case then or otherwise, i can't verify nor explain this problem.