Hi, I just decide to change my kinematic ship to be an rigidbody ship. Its using joints to simulate fixed orbit around a planet.
Then I found out a odd behavior when it reaches some positions in space, it seems it just remove all torque forces and then invert it…
I am using obj.applyTorque(new Vector3f(0,1,0)) , but I also tried to change the vector to the foward+90º from the ship, didnt work…
I just built an test case for it, and made this image of the positions…
I am not sure if this is a bug, an problem in my code, an problem with joints, or an misunderstanding on how torque works, so if anyone that knows it better could clarify me I appreciate.
http://s24.postimg.org/4mtya5xad/torquebug.png
public class RestrictionTest extends SimpleApplication implements PhysicsTickListener {
private BulletAppState bulletAppState;
private boolean keyup,keyleft,keyright,keydown;
private Node coneObjNode;
private ConeJoint conejoint;
public RestrictionTest() {super(null);}
public static void main(String[] args) { new RestrictionTest().start(); }
@Override public void simpleInitApp() {
bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
bulletAppState.getPhysicsSpace().setGravity(Vector3f.ZERO);
bulletAppState.getPhysicsSpace().enableDebug(assetManager);
Node centerConeNode=new Node(); centerConeNode.setLocalTranslation(0, -0, 0f);
coneObjNode=new Node(); coneObjNode.setLocalTranslation(0,-2f,0f);
BoxCollisionShape collisionShape = new BoxCollisionShape(new Vector3f( .3f, .3f, .3f));
conejoint = Utils.createConeJoint(centerConeNode, coneObjNode, collisionShape, 1, bulletAppState);
rootNode.attachChild(centerConeNode); rootNode.attachChild(coneObjNode);
bulletAppState.getPhysicsSpace().add(conejoint);
// *******************
// Front Debug Arrow
Material mFoward = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
Vector3f directionFoward = new Vector3f(0, 0, 1f);
Arrow arrowFoward = new Arrow(directionFoward); arrowFoward.setLineWidth(2); Geometry gArrowFoward = new Geometry("aaa",arrowFoward);
mFoward.setColor("Color", ColorRGBA.Gray); gArrowFoward.setMaterial(mFoward);
coneObjNode.attachChild(gArrowFoward);
// *******************
// Right Debug Arrow
Material mRight = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
Vector3f directionRight = new Vector3f(1, 0, 0);
Arrow arrowRight = new Arrow(directionRight); arrowRight.setLineWidth(2); Geometry gArrowRight = new Geometry("aaa",arrowRight);
mRight.setColor("Color", ColorRGBA.Red); gArrowRight.setMaterial(mRight);
coneObjNode.attachChild(gArrowRight);
conejoint.getBodyB().setDamping(0.5f, 0.9f);
inputManager.addMapping("left", new KeyTrigger(KeyInput.KEY_LEFT)); inputManager.addMapping("left", new KeyTrigger(KeyInput.KEY_A ));
inputManager.addMapping("right", new KeyTrigger(KeyInput.KEY_RIGHT)); inputManager.addMapping("right", new KeyTrigger(KeyInput.KEY_D));
inputManager.addMapping("up", new KeyTrigger(KeyInput.KEY_UP)); inputManager.addMapping("up", new KeyTrigger(KeyInput.KEY_W));
inputManager.addMapping("down", new KeyTrigger(KeyInput.KEY_DOWN)); inputManager.addMapping("down", new KeyTrigger(KeyInput.KEY_S));
inputManager.addListener(actionListener, "up","left","right","down");
bulletAppState.getPhysicsSpace().addTickListener(this);
}
private ActionListener actionListener = new ActionListener() {
public void onAction(String name, boolean keyPressed, float tpf) {
if (name.equals("up")) keyup=keyPressed;
if (name.equals("left")) keyleft=keyPressed;
if (name.equals("right")) keyright=keyPressed;
if (name.equals("down")) keydown=keyPressed;
}
};
public void prePhysicsTick(PhysicsSpace space, float tpf) {
Quaternion fixit = conejoint.getBodyA().getPhysicsRotation();
fixit.lookAt(coneObjNode.getWorldTranslation(), Utils.getForwardVector(coneObjNode) );
conejoint.getBodyA().setPhysicsRotation(fixit);
Vector3f foward = Utils.getForwardVector((Node)coneObjNode);
PhysicsRigidBody obj = conejoint.getBodyB();
if (keyup) { obj.applyForce(foward, coneObjNode.getWorldTranslation() ); }
if (keydown) { obj.applyForce(foward.negate(), coneObjNode.getWorldTranslation() ); }
if(keyleft) { obj.applyTorque(new Vector3f(0,1,0)); }
if(keyright) { obj.applyTorque(new Vector3f(0,-1,0)); }
}
public void physicsTick(PhysicsSpace space, float tpf) { }
}