Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Below is the code for one of my objects in the game I am creating (yes although this is a cube, I am not making anything remotely like MineCraft), and my issue is I while the cube will display and is does follow the physics if the cube falls, it does not interact with any other objects in the game. If I was to have multiple cubes in screen at once they all just sit there, or shoot off in all directions never stopping. Anyway, I am new to jBullet, and any help would be appreciated.

    // Constructor
public Cube(float pX, float pY, float pZ, float pSize)  {
    posX = pX;
    posY = pY;
    posZ = pZ;
    size = pSize;
    rotX = 0;
    rotY = 0;
    rotZ = 0;

    // physics stuff
    fallMotionState = new DefaultMotionState(new Transform(new Matrix4f(new Quat4f(0, 0, 0, 1), new Vector3f(posX, posY, posZ), 1)));
    fallRigidBodyCI = new RigidBodyConstructionInfo(mass, fallMotionState, fallShape, fallInertia);
    fallRigidBody = new RigidBody(fallRigidBodyCI);
}
share|improve this question
2  
Welcome to GDSE. We're not fixing bugs, take a look at FAQ: gamedev.stackexchange.com/faq Stack Exchange is about solving repeatable problems. Please rephrase your question in the way it may in future show up in google for someone else having a similar problem. Changing title and replacing the code with a special case designed just to show the problem would be a good start. –  Markus von Broady Oct 21 '12 at 21:30
1  
Move fallShape.calculateLocalInertia(mass, fallInertia); to before you create RigidBodyConstructionInfo –  msell Oct 22 '12 at 5:28
    
I will give that a shot! thank you! –  Kenneth Bray Oct 22 '12 at 16:20
    
I tried your recommendation msell, but everything still just kinda doesnt sit where they are coded to. They just fly around.. I think my issue is on the below line, any ideas? fallMotionState = new DefaultMotionState(new Transform(new Matrix4f(new Quat4f(0, 0, 0, 1), new Vector3f(posX, posY, posZ), 1))); –  Kenneth Bray Oct 22 '12 at 22:02
add comment

1 Answer

up vote 1 down vote accepted

From the given code I cannot say what the problem could be. The following code is working fine for me.

First create the physics world:

// Create the physics world
BroadphaseInterface broadphase = new DbvtBroadphase();
CollisionConfiguration collisionConfiguration = new DefaultCollisionConfiguration();
Dispatcher dispatcher = new CollisionDispatcher(collisionConfiguration);
ConstraintSolver solver = new SequentialImpulseConstraintSolver();
DiscreteDynamicsWorld dynamicsWorld =
    new DiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);
dynamicsWorld.setGravity(new Vector3f(0, gravity, 0));

Then create physics objects:

// Create a physics object (sphere)
MotionState motionState = new DefaultMotionState();
CollisionShape collisionShape = new SphereShape(radius);
Vector3f localInertia = new Vector3f(0, 0, 0);
collisionShape.calculateLocalInertia(mass, localInertia);
RigidBody rigidBody = new RigidBody(mass, motionState, collisionShape, localInertia);
rigidBody.setActivationState(CollisionObject.DISABLE_DEACTIVATION);
Transform transform = new Transform();
transform.origin.set(x, y, z);
rigidBody.setWorldTransform(transform);

And finally add the physics object to the physics world:

// Add the object to the world
dynamicsWorld.addRigidBody(rigidBody);
share|improve this answer
    
That helped out quite a bit, I like the activationstate disabling deactivation. –  Kenneth Bray Oct 24 '12 at 3:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.