jME3 Preventng PhysicsNode rotation on a specific axis

Hello!



I searched around the forum but couldn’t find a post about this. I’ve tried countering the rotational force in simpleUpdate by using something similar to:



[java]

Vector3f rar = player.getAngularVelocity();

System.out.println(rar);



player.applyTorqueImpulse(new Vector3f(-rar.x, 0, -rar.z));

// player.setAngularVelocity(new Vector3f(0,0,0));

// player.updatePhysicsState();

[/java]



However, all it does is slow the forces to a crawl, which I imagine means that this update is getting to the next physics update with smaller values than the freshest values in the physics pass (as per discussions long ago). Is there a way to counter this force on the next physics update?



Thanks!

~FlaH

No switch that works properly in jbullet, no. The setAnguarVelocity() thing doesnt work?

Hello!



Sure enough it didn’t. It just slowly… Very slowly, tilts and falls over. Now, this is using a capsule shape, not a cylinder so there might be some stupidity on my part for attempting such a thing, but it seemed to me if I was canceling that force that it shouldn’t matter. I tried various ways, but they all ended the same. The topic: http://hub.jmonkeyengine.org/groups/physics/forum/topic/collision-between-two-physicscharacternode/#post-111526 made me think about this all over again. PhysicsCharacterNode is nice, it’s just that it’s a good start, rather than an end result for a lot of applications. XD



I’ll probably keep using the CharacterNode for what I’m doing since it’s enough for now, but it’s going to be a pain as soon as I start doing things like elevators or ladders (Detaching and reattaching all over the place etc etc ~ Actually, I already do a little of this for resizing the physics shape for crouching ;p). But I fear even if I moved to a full blown PhysicsNode if I’d even be smart enough to keep the thing from going out of control! XD



The code I was playing with is below:



~FlaH



[java]

public class TestPhysicsPlayer extends SimpleApplication {



private static AppSettings settings;

private BulletAppState bulletAppState;



PhysicsNode floor;

PhysicsNode player;



public static void main(String[] args) {

TestPhysicsPlayer app = new TestPhysicsPlayer();

settings = new AppSettings(true);

settings.setFrameRate(200);

settings.setTitle(“Physics Player Experiment”);

app.setSettings(settings);

app.start();

}



@Override

public void simpleInitApp() {

flyCam.setMoveSpeed(15f);



// Init Bullet Application State

bulletAppState = new BulletAppState();

bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);

stateManager.attach(bulletAppState);



// Init Floor

floor = new PhysicsNode(new BoxCollisionShape(new Vector3f(10, 0.5f, 10)), 0);

floor.attachDebugShape(getWireframeMat(ColorRGBA.Blue));

floor.setLocalTranslation(0, -0.5f, 0);

// floor.setRestitution(1.0f);

rootNode.attachChild(floor);

bulletAppState.getPhysicsSpace().add(floor);



// Init Player Object

player = new PhysicsNode(new CapsuleCollisionShape(0.75f, 3, 1), 1);

player.attachDebugShape(getWireframeMat(ColorRGBA.Green));

player.setLocalTranslation(0, 5, 0);

player.setSleepingThresholds(0.05f, 0.05f);

// player.setRestitution(1.0f);

rootNode.attachChild(player);

bulletAppState.getPhysicsSpace().add(player);



bulletAppState.getPhysicsSpace().addTickListener®;

}



@Override

public void simpleUpdate(float tpf) {

super.simpleUpdate(tpf);



Vector3f rar = player.getAngularVelocity();

System.out.println(rar);



// heh, worked, with side effects

// player.setPhysicsRotation(new Matrix3f(0, 0, 0, 0, 0, 0, 0, 0, 0));



// player.applyTorqueImpulse(new Vector3f(-rar.x, 0, -rar.z));

// player.setAngularVelocity(new Vector3f(0,0,0));

// player.updatePhysicsState();

}



PhysicsTickListener r = new PhysicsTickListener() {

@Override

public void physicsTick(PhysicsSpace space, float f) {

player.clearForces();

// player.applyTorqueImpulse(player.getAngularVelocity().negate());

player.setAngularVelocity(new Vector3f(0,0,0));

}

};



public Material getWireframeMat(ColorRGBA color) {

Material mat = new Material(assetManager, “Common/MatDefs/Misc/WireColor.j3md”);

mat.setColor(“m_Color”, color.clone());



return mat;

}

}

[/java]

Actuall yif you wnat ot change the way stuff works completly, like a reziesable physic node, you may want to acces jbullet directly for this (keep in midn that when normen changes to native bullet this will fail then and you have to reimplement)



However you could easylie change shapes ect then without the need to to such comlicated stuff.

Well if you really try around with jbullet itself (most of its functions are accessible via the jME api anyway) and get some results, post them back here and we see how it can be integrated. But really, most stuff is wrapped. I know that the way native bullet locks axes does not work in jbullet, so the proper feature will be added in jME when physics goes native.

Hello!



Sounds good, I was just messing around with the idea anyway. I saw all the other threads about locking axis but no one ever actually went into depth on how to do it; so it led me to believe it was possible, just no one wanted to say how :slight_smile:



Also, I know I post a lot of threads about physics so I just want to say that I appreciate all the work you’ve done with jBullet Normen! I’ve done some pretty funny/neat things with the physics in my off time, I just never post about all the things that work :wink: It really is a pretty neat set of physics simulation tools.



Thanks!

~FlaH