Author Topic: Collision between 2 models.  (Read 5608 times)

Offline dl.zerocool

  • long
  • ***
  • Posts: 104
    • View Profile
Collision between 2 models.
« on: May 30, 2010, 04:32:12 pm »
Hi,

I'm using :
Code: [Select]
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.
Code: [Select]
if(cId==NO_OJBECT)then I move
else
do something else.

My projectiles are configured like this when I create a project :
Code: [Select]
       addCollisionListener(this);
setCollisionMode(COLLISION_CHECK_SELF);
setCollisionOptimization(COLLISION_DETECTION_OPTIMIZED);

Now the objects I want to collide with have this settings
Code: [Select]
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 ?



Offline dl.zerocool

  • long
  • ***
  • Posts: 104
    • View Profile
Re: Collision between 2 models.
« Reply #1 on: May 30, 2010, 05:18:24 pm »
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 ?

Offline dl.zerocool

  • long
  • ***
  • Posts: 104
    • View Profile
Re: Collision between 2 models.
« Reply #2 on: May 30, 2010, 05:53:10 pm »
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];
« Last Edit: May 30, 2010, 06:00:29 pm by dl.zerocool »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Collision between 2 models.
« Reply #3 on: May 30, 2010, 09:38:03 pm »
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.
« Last Edit: May 30, 2010, 09:57:20 pm by EgonOlsen »

Offline dl.zerocool

  • long
  • ***
  • Posts: 104
    • View Profile
Re: Collision between 2 models.
« Reply #4 on: May 31, 2010, 01:16:42 am »
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.

Offline dl.zerocool

  • long
  • ***
  • Posts: 104
    • View Profile
Re: Collision between 2 models.
« Reply #5 on: May 31, 2010, 09:30:03 am »
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 ;)

Offline smither

  • byte
  • *
  • Posts: 13
    • View Profile
Re: Collision between 2 models.
« Reply #6 on: September 15, 2010, 04:50:36 pm »
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