211
Support / Re: Inconsistency in collision detection
« on: September 23, 2011, 10:52:03 am »
I'm having a bit of difficulty placing an Object3D (an MD2 character) on the ground. I got it working, but the character ends up too high off the ground, so I hack the offset by 20.
The ground is an Object3D plane created with Primitives and modified by a VertexController
terrain = Primitives.getPlane(50, 50);
terrain.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
On every frame I call this function:
My question is, how do you determine the height or bottom of the 3D Object and place it on the ground properly without hacking the value?
Do I need to use the ellipse method?
Or scale the value returned by calcMinDistance() to the world scale?
The ground is an Object3D plane created with Primitives and modified by a VertexController
terrain = Primitives.getPlane(50, 50);
terrain.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
On every frame I call this function:
Code: [Select]
private void ObjectToGround(Object3D object)
{
SimpleVector sv = new SimpleVector();
// Get object position
sv = object.getTranslation();
// Determine height above terrain
float terrHeight = terrain.calcMinDistance(sv, new SimpleVector(0,1,0));
if(terrHeight == Object3D.COLLISION_NONE)
{
//Log.v(TAG, "COLLISION_NONE" );
}
else
{
//sv.scalarMul(terrHeight); // object goes underground
terrHeight -= 20; // Hack offset
sv.set(0, terrHeight, 0);
character.translate(sv);
}
}
My question is, how do you determine the height or bottom of the 3D Object and place it on the ground properly without hacking the value?
Do I need to use the ellipse method?
Or scale the value returned by calcMinDistance() to the world scale?