Moving a RigidBody

Hello everyone,



I would like to move my RigidBody, here is the code that i use :



[java]

public void simpleInitApp() {

// …

Box b1=new Box(Vector3f.ZERO, 0.6f, 0.6f, 0.6f);

geom1 = new Geometry("Box", b1);

geom1.updateModelBound();

Material matp = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");

assetManager.registerLocator("assets/Textures/", FileLocator.class);

Texture tex_ml = assetManager.loadTexture("player.png");

matp.setTexture("ColorMap", tex_ml);

geom1.setMaterial(matp);

geom1.move(0, 25f, 0);



BoxCollisionShape playerShape = new BoxCollisionShape(new Vector3f(0.6f, 0.6f, 0.6f));

player = new RigidBodyControl(playerShape, 3);

geom1.addControl(player);

// …

}

public void simpleUpdate(float tpf) {

// …

Vector3f v = new Vector3f(0,0,0);

if (left) { v.x -= 4f; }

if (right) { v.x += 4f; }

if (up) { v.z -= 4f; }

if (down) { v.z += 4f; }

if( left || right || up || down){



player.setLinearVelocity(v);

//…

}

[/java]



And here is the result :



http://www.youtube.com/watch?v=aRRZ9QGupRA



As you can see in the video, the box rotate when i move it up & down, how can i move it without rotating ?

Thank you,
Akram Fares

Set it to kinematic mode if you don’t want to move it by physics forces and have physics reactions. If you really want to lock rotation you can do that with rigidBody.setAngularFactor(0);

Thank’s normen for your fast answer,



1 - When i set the player.setAngularFactor(0), the rigidbody don’t rotate but he move a little bit to right and left (i move it just up and down)

2 - When i set the kinematic mode player.setKinematic(true), the box don’t fall :confused:

  1. try to put one finger on the center of a cigarette box and slide it perfectly straight across the table
  2. yeah, thats the point, check the javadoc

There is not a simple way to move the box in a straight line with collision detection?

Sure, use kinematic rigidbodies. See you have to divide in your mind between collision detection, physics simulation and the actual objects you see moving on the screen.

But when i set the kinematic, the box don’t even fall …



Can you give me an example please.

Look, if you want physics to act on your body (which it doesn’t in kinematic mode, as said thats the point, it only acts on other physics objects and you can move it by setting its location instead of applying forces, again, read the javadoc of the method) you will have to counter-act it like a planes fly-by-wire system or Nissan’s robot that manages to walk on two legs. If you don’t want that then don’t apply physics and do other things to keep your objects from colliding like for example sweepTests for collision with objects and a raytest downwards for the floor-tracking (which is what the bullet Character does).

1 Like