I'm currently trying to make a ball in a straight line using the bullet version included with libGDX (therefore, Java). I've a very weird issue where the same ball, set at the origin is moved to a wrong position when applied a force and when issued a simulation step. The sphere has been recently created.
For exemple, here's what the log returns:
And here's the code, so you can have a point of reference:07-06 16:21:12.160 8285-9100/pt.bluecover.wearable3d I/System.out: UPDATE: Sphere is @ (0.0,0.0,0.0) @ 0.011
07-06 16:21:12.160 8285-9100/pt.bluecover.wearable3d I/System.out: UPDATE: Acceleration is (-9.780663,-0.6153471,0.0)
07-06 16:21:12.160 8285-9100/pt.bluecover.wearable3d I/System.out: UPDATE: Linear Velocity is (0.0,0.0,0.0)
07-06 16:21:12.160 8285-9100/pt.bluecover.wearable3d I/System.out: DELTA TIME: 0.01650481
07-06 16:21:12.170 8285-9100/pt.bluecover.wearable3d I/System.out: UPDATE: Sphere is @ (0.2504366,0.014636279,0.0) @ 0.018
07-06 16:21:12.170 8285-9100/pt.bluecover.wearable3d I/System.out: UPDATE: Acceleration is (-9.780663,-0.6153471,0.0)
07-06 16:21:12.170 8285-9100/pt.bluecover.wearable3d I/System.out: UPDATE: Linear Velocity is (-0.08149039,-0.0053867875,0.0)
07-06 16:21:12.170 8285-9100/pt.bluecover.wearable3d I/System.out: DELTA TIME: 0.014863175
Code: Select all
if(starting) {
startTime = TimeUtils.millis();
starting = false;
return;
}
double miliTime = TimeUtils.millis();
double time = (miliTime - startTime) / 1000;
//get sphere position
Vector3 position = new Vector3();
sphereInstance.transform.getTranslation(position);
System.out.println("UPDATE: Sphere is @ " + position + " @ " + time);
spawnTrailPoint(position, time);
if(loader != null) try {
DataSet curr = loader.find(time);
Vector3 acc = curr.acceleration.cpy().scl(9.8f); //acceleration is a 3D vector
System.out.println("UPDATE: Acceleration is " + acc);
System.out.println("UPDATE: Linear Velocity is " + sphereInstance.body.getLinearVelocity());
Quaternion orientation = sphereInstance.body.getOrientation(); //the body attribute is a btRigidBody type
sphereInstance.body.applyCentralForce(acc);
} catch (NoMoreElementsException ex) {
(Stuff to finish movement here)
}
float dt = Gdx.graphics.getDeltaTime(); //get time before last frame.
System.out.println("DELTA TIME: " + dt);
dynamicsWorld.stepSimulation(dt, 10, 1f/60f);
Also, if you need me to add more code, please just say so!