jPCT-AE - a 3d engine for Android > Support

Inconsistency in collision detection

(1/5) > >>

Tishu:
Hello

I am using collision detection from a plane to a point using the calcMinDistance method. I use the following code:


--- Code: ---public double checkLeftGearCollisionDz(double modelDz)
{
final SimpleVector uiDz = new SimpleVector(0, -1, 0);
final float minDist = ground.calcMinDistance(leftGear.getTransformedCenter(), uiDz);
if(!(minDist == Object3D.COLLISION_NONE) && minDist > modelDz) // values are <0
{
return 0;
//return minDist < 0.5 ? 0 : minDist*modelDz;
}
return Object3D.COLLISION_NONE;
}

--- End code ---

I place my plane a bit over the ground, and it falls nicely on it. Collision works fine, as I can see in the figues I write in the logs. Then I start rolling forward, and at some point it will fail. The values I pass to the collision detection are consistent though:


--- Code: ---Z before(22996): 4.150430202484131
dZ tentative(22996): -0.11481471204757691
actual dZ(22996): 0.0

Z before(22996): 4.150430202484131
dZ tentative(22996): -0.10089619320631027
actual dZ(22996): 0.0

Z before(22996): 4.150430202484131
dZ tentative(22996): -0.12035272479057313
actual dZ(22996): 0.0

Z before(22996): 4.150430202484131
dZ tentative(22996): -0.10804409158229827
actual dZ(22996): -0.10804409158229827

--- End code ---

Z before is the position of the plane before calcMinDistance. This remains constant. On each frame I try to move the plane by dZ tentative and check if this makes it collide with the ground. If yes, I use 0 for actual dZ.
On the last frame, my Z before has not changed, the dZ tentative is a value I have tried before, but calcMinDistance returns Object3D.COLLISION_NONE and actual dZ is non zero -> the plane goes trough the ground.

I have taken a look at this thread
http://www.jpct.net/forum2/index.php/topic,1376.msg9655.html#msg9655
I increased the value of collideOffset to 500 with no success (even tried 5000, made no difference)

I also saw this one
http://www.jpct.net/forum2/index.php/topic,335.msg1825.html#msg1825
And I tried using an octree:


--- Code: ---final Object3D world = loadGround(is, 1);
world.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
final OcTree o = new OcTree(world, 100, OcTree.MODE_OPTIMIZED);
o.setCollisionUse(OcTree.COLLISION_USE);
world.setOcTree(o);     
world.setCollisionOptimization(Object3D.COLLISION_DETECTION_OPTIMIZED);
r.ground = world;

--- End code ---

Tried difference values for the maxPoly. I get a StackOverFlowException for values <100, and no difference in collision detection for values >100.

It seems to me that there is an area in the ground where collision just won't happen.

Thx
Nicolas

EgonOlsen:
What is modelDz? I'm a bit puzzled about this "minDist > modelDz"-condition...have you checked the actual return value of calcMinDistance in the case that has the problem? I would be interested if the method itself returns "no collision" or if you "invent" this with this condition in your code!?

Tishu:
It does return COLLISION_NONE.

modelDz is how much the model would like the plane to move. I check how much I can move in that direction (minDist, which should rather be called maxDz), and I can move less that what the model wants to move, I stay still Z-axis wise.

I really think there is like  a "hole" in the ground, as no matter how I approach it, it goes trough the floor at the same place.

Thx
Nic

Tishu:
To illustrate this, rolling always is fine until I get to the point on the picture below. I can see the end of a face (with the texture being discontinuous) and when I get to the next one, I fall through it.

Tishu:
It seems that the sign of the return value of calcMinDistance is dictated by the direction of the normal of my plane. I fixed the normals in Blender and it works good now.

Thx
Nic

Edit: Correction before I'm told off by EgonOlsen :), if does not just dictate the sign of the return value, it seems to dictate the direction where it moves for collision detection, hence sometimes I got COLLISION_NONE as it was moving in the opposite direction

Navigation

[0] Message Index

[#] Next page

Go to full version