Collision between 2 models.

Started by dl.zerocool, May 30, 2010, 04:32:12 PM

Previous topic - Next topic

dl.zerocool

Hi,

I'm using :
cId = checkForCollision(dir, step);
where step =2f and dir is a direction SimpleVector from a projectile (he moves along this dir)

My problem is :

I've a projectile :  That I want to move except if there's a collision and in this case I want to do something else.
So basicaly I use checkForCollision each time before moving.
if(cId==NO_OJBECT)
then I move
else
do something else.

My projectiles are configured like this when I create a project :

       addCollisionListener(this);
setCollisionMode(COLLISION_CHECK_SELF);
setCollisionOptimization(COLLISION_DETECTION_OPTIMIZED);


Now the objects I want to collide with have this settings

addCollisionListener(this);
setCollisionMode(COLLISION_CHECK_OTHERS);
setCollisionOptimization(COLLISION_DETECTION_OPTIMIZED);


The problem is that even I'm seeing that the 2 objects are colliding cID still equal to NO_OBJECT
so no collision detected.


Am I doing something wrong ?



dl.zerocool

Well sometimes it works...

But it's like It have to touch exactly the center of the object. Not the bounding box.

Do I need to do something special ? Add a box around my models or something else ?

dl.zerocool

#2
Okay it worked with big models.

Apparently due to imprecision of my movement with sensors it's very difficult to get a target in the ray way.

Is it possible to grow bouding box without having to set it again completly ?

Because I don't know how to calculate it, and something like -> setBoundingBoxScale(float f)
would be awesome.

[edit]
another question is boudingBox calculate with the scale factor ? Here 20f for example.
Loader.load3DS(res.openRawResource(R.raw.bear), 20f)[0];

EgonOlsen

#3
The bounding box does scale with scaling but that doesn't really matter, because collisions in jPCT are always ray/sphere/ellipsoid against polygons, not against the bounding box. That means that your ray (cast from the center of the colliding object) has to hit one of the polygons of the other object. Maybe that's not always the case in your application!? You might try to use spherical or ellipsoid collision detection instead, where the colliding object has an actually "size" and isn't a simple ray with no size at all.

dl.zerocool

I will try with elipsoid, but tomorrow (need some sleep) Thanks for advice.

and probably that's the problem, because at moment I do see the objects going trough each other and only in very few cases collisions occur.

Thank you.

dl.zerocool

Well I just changed how I do things and reworked my model changed the center to middle of the models and not the feets, apparently it works better.
But perhaps it can be improved.
I'll share results tomorrow ;)

smither

I'd run in the same problem, sometimes the collision worked and sometimes didn't. I was using the ellipsoid approach, I decreased the ellipse size and started to work for all the cases.  :D