Hi everyone! I have problem with the "Compound Shape". I changed the method "BulletPhysics.getShapeFor" by adding compoundShape in it. And I added the "offset" value in the RigidBodyComponent (I did it for the shift of the center of mass ) But, when I start the Terasology and create the entity with the compound shape, the entity will falls down to ignoring the collision with the world =(
Here is the method code:
Can anybody help me? =(
Here is the method code:
Code:
private CollisionShape getShapeFor(EntityRef entity) {
BoxShapeComponent box = entity.getComponent(BoxShapeComponent.class);
RigidBodyComponent rb = entity.getComponent(RigidBodyComponent.class);
ConvexShape shape = null;
if (box != null) {
Vector3f halfExtents = new Vector3f(box.extents);
halfExtents.scale(0.5f);
shape = new BoxShape(halfExtents);
}
SphereShapeComponent sphere = entity.getComponent(SphereShapeComponent.class);
if (sphere != null) {
shape = new SphereShape(sphere.radius);
}
CapsuleShapeComponent capsule = entity.getComponent(CapsuleShapeComponent.class);
if (capsule != null) {
shape = new CapsuleShape(capsule.radius, capsule.height);
}
CylinderShapeComponent cylinder = entity.getComponent(CylinderShapeComponent.class);
if (cylinder != null) {
shape = new CylinderShape(new Vector3f(cylinder.radius, 0.5f * cylinder.height, cylinder.radius));
}
HullShapeComponent hull = entity.getComponent(HullShapeComponent.class);
if (hull != null) {
ObjectArrayList<Vector3f> verts = new ObjectArrayList<Vector3f>();
TFloatIterator iterator = hull.sourceMesh.getVertices().iterator();
while (iterator.hasNext()) {
Vector3f newVert = new Vector3f();
newVert.x = iterator.next();
newVert.y = iterator.next();
newVert.z = iterator.next();
verts.add(newVert);
}
shape = new ConvexHullShape(verts);
}
if ( rb != null && rb.offset != null && rb.offset.length() > 0 ){
CompoundShape compoundShape = new CompoundShape();
Transform localTransform = new Transform();
localTransform.setIdentity();
localTransform.origin.set(rb.offset);
compoundShape.addChildShape(localTransform, shape);
return compoundShape;
}
if ( shape != null ){
return shape;
}
CharacterMovementComponent characterMovementComponent = entity.getComponent(CharacterMovementComponent.class);
if (characterMovementComponent != null) {
return new CapsuleShape(characterMovementComponent.radius, characterMovementComponent.height);
}
logger.error("Creating physics object that requires a ShapeComponent or CharacterMovementComponent, but has neither. Entity: {}", entity);
throw new IllegalArgumentException("Creating physics object that requires a ShapeComponent or CharacterMovementComponent, but has neither. Entity: " + entity);
}