try {
playerDummyObj = Object3D.createDummyObj();
AssetManager.AssetInputStream fis = (AssetManager.AssetInputStream) MainActivity.MA.getResources().openRawResource(
R.raw.terra);
playerObj3d = Loader.loadASC(fis, SCALE*0.20F, true);
playerObj3d.setTexture("cliff");
AssetManager.AssetInputStream fisShield = (AssetManager.AssetInputStream) MainActivity.MA.getResources().openRawResource(
R.raw.terra);
shieldBall = Loader.loadASC(fisShield, SCALE*0.20F, true);
shieldBall.setTexture("cliff");
} catch (Exception e) {
e.printStackTrace();
}
MainActivity.WORLD.addObject(playerObj3d);
MainActivity.WORLD.addObject(shieldBall);
Transform shapeTransform = new Transform();
shapeTransform.setIdentity();
shapeTransform.origin.set(new Vector3f(0F, 0.5F, 0F));
Transform shieldBallTransform = new Transform();
shieldBallTransform.setIdentity();
shieldBallTransform.origin.set(new Vector3f(0.5F, 0.5F, 0F));
SphereShape shape = new SphereShape(1F);
shape.setLocalScaling(new Vector3f(SCALE,SCALE,SCALE));
SphereShape shieldBallShape = new SphereShape(1F);
shieldBallShape.setLocalScaling(new Vector3f(SCALE,SCALE,SCALE));
Vector3f localInertia = new Vector3f(0, 0, 0);
Vector3f shieldLocalInertia = new Vector3f(0, 0, 0);
shape.calculateLocalInertia(mass, localInertia);
shieldBallShape.calculateLocalInertia(mass, shieldLocalInertia);
JPCTBulletMotionState ms = new JPCTBulletMotionState(playerObj3d, shapeTransform);
RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(mass, ms, shape, localInertia);
body = new RigidBody(rbInfo);
Jbullet.dynamicWorld.addRigidBody(body);
JPCTBulletMotionState msShield = new JPCTBulletMotionState(shieldBall, shieldBallTransform);
RigidBodyConstructionInfo rbInfoShield = new RigidBodyConstructionInfo(mass, msShield, shieldBallShape, shieldLocalInertia);
RigidBody shieldBody = new RigidBody(rbInfoShield);
Jbullet.dynamicWorld.addRigidBody(shieldBody);
playerDummyObj.translate(0F, 2F, 0F);
shieldBall.addParent(playerDummyObj);
new Thread(new Runnable() {
@Override
public void run() {
while (true) {
// playerDummyObj.clearTranslation();
playerDummyObj.rotateAxis(playerDummyObj.getRotationMatrix().getYAxis(),-0.02f);
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
Hello, I have such a code and my problem is to get shieldBall run around the invisible playerDummyObj with Y axis.
What I observe is: nothing happens in a few seconds, then rapidly shieldBall rotates around itself and goes away in three directions at the same time very fast (it's like a photon
)
Any idea how to make my shieldBall slowly run around playerDummyObj like an earth around the sun?