return createCustomCollider(pos, shape, movementComp.collisionGroup.getFlag(), combineGroups(movementComp.collidesWith),
CollisionFlags.CHARACTER_OBJECT, owner);
}
private RigidBody newRigidBody(EntityRef entity) {
LocationComponent location = entity.getComponent(LocationComponent.class);
RigidBodyComponent rigidBody = entity.getComponent(RigidBodyComponent.class);
ConvexShape shape = getShapeFor(entity);
if (location != null && rigidBody != null && shape != null) {
float scale = location.getWorldScale();
shape.setLocalScaling(new Vector3f(scale, scale, scale));
if (rigidBody.mass < 1) {
logger.warn("RigidBodyComponent.mass is set to less than 1.0, this can lead to strange behaviour, such as the objects moving through walls. " +
"Entity: {}", entity);
}
Vector3f fallInertia = new Vector3f();
shape.calculateLocalInertia(rigidBody.mass, fallInertia);
RigidBodyConstructionInfo info = new RigidBodyConstructionInfo(rigidBody.mass, new EntityMotionState(entity), shape, fallInertia);
BulletRigidBody collider = new BulletRigidBody(info);
collider.rb.setUserPointer(entity);
collider.rb.setAngularFactor(rigidBody.angularFactor);
collider.rb.setLinearFactor(rigidBody.linearFactor);
collider.rb.setFriction(rigidBody.friction);
collider.collidesWith = combineGroups(rigidBody.collidesWith);
updateKinematicSettings(rigidBody, collider);
BulletRigidBody oldBody = entityRigidBodies.put(entity, collider);
addRigidBody(collider, Lists.<CollisionGroup>newArrayList(rigidBody.collisionGroup), rigidBody.collidesWith);
if (oldBody != null) {
removeRigidBody(oldBody);
}
collider.setVelocity(rigidBody.velocity, rigidBody.angularVelocity);
collider.setTransform(location.getWorldPosition(), location.getWorldRotation());
return collider;
} else {
throw new IllegalArgumentException("Can only create a new rigid body for entities with a LocationComponent," +
" RigidBodyComponent and ShapeComponent, this entity misses at least one: " + entity);
}