First of all, I'd like to apologize if a topic describing this already exists, but I've spent the past two weeks trying different resources Google threw up with no luck. I'm brand new to Bullet Physics with general knowledge of Linear Algebra. I'm designing a mobile maze game, which uses accelerometer input for board dynamic rotation because of which a ball would be forced to move by physics.
This is designed using a kinematic body for the 'table' and a dynamic rigid body for the ball, however, when table is rotated too quickly the ball shoots out into the sky.
I create objects with this code as part of create method
Code: Select all
instances = new Array<Entity>();
Entity object = constructors.get("ground").create();
object.body.setCollisionFlags(object.body.getCollisionFlags() | btCollisionObject.CollisionFlags.CF_KINEMATIC_OBJECT);
object.body.setHitFraction(0);
object.body.setRollingFriction(0.1f);
object.transform.setFromEulerAngles(0, 0, 0);
object.body.proceedToTransform(object.transform);
instances.add(object);
dynamicsWorld.addRigidBody(object.body);
object.body.setContactCallbackFlag(GROUND_FLAG);
object.body.setContactCallbackFilter(0);
object = constructors.get("sphere").create();
object.transform.trn(0, 4.5f, 0);
object.body.proceedToTransform(object.transform);
object.body.setUserValue(instances.size);
object.body.setCollisionFlags(object.body.getCollisionFlags() | btCollisionObject.CollisionFlags.CF_CUSTOM_MATERIAL_CALLBACK);
object.body.setDamping(0.1f, 0.1f);
object.body.setLinearVelocity(new Vector3(0, -1, 0));
object.body.setFriction(0.1f);
instances.add(object);
dynamicsWorld.addRigidBody(object.body);
object.body.setContactCallbackFlag(OBJECT_FLAG);
object.body.setContactCallbackFilter(GROUND_FLAG);
object.body.setActivationState(Collision.DISABLE_DEACTIVATION);
Code: Select all
accelerometer.update();
final float delta = Math.min(1f / 60f, Gdx.graphics.getDeltaTime());
rotation.setEulerAngles(0, ((((accelerometer.axisY() * 10) / 10f) / 10) * 90), ((((accelerometer.axisX() * 10) / 10f) / 10) * 90));
instances.get(0).transform.idt().rotate(rotation).translate(0, 0, 0);
instances.get(0).body.setActivationState(Collision.ACTIVE_TAG);
dynamicsWorld.stepSimulation(delta, 5, 1f / 120f);
Please feel free to check it out, the latest commit has code and commented out scraps of previous effort. Let me also mention that this project is my school project which must be finished in less than 30 days, meaning I would really appreciate any help at all. Thanks in advance.
Regards,
Lucky