Creating a gravity

Hey guys, how can I create a gravity? Like, when a object (without being a certanly node (my floor)) is floating, it falls?

I don't know if this information is needed, but I'm using NetBeans.

You can use a physics implementation like jbullet-jme or jmephysics2. Theres lots of information about both in this forum and the project sites.



Cheers,

Normen

Can you give me a example of using it?

Despite the fact that the example was just two clicks away in my first answer I will give you a direct link.

Ok, i Have just downloaded it, the aplha one, added the jars to my project, but when I'm trying to make the basic example, netbeans can't find SPHERE, and I already tried without that parameter, but the object stills floating.


GustavoBorba said:

Ok, i Have just downloaded it, the aplha one, added the jars to my project, but when I'm trying to make the basic example, netbeans can't find SPHERE, and I already tried without that parameter, but the object stills floating.

Do you call PhysicsSpace.getPhysicsSpace().update(tpf) in your jme update method?

I tried to update, but it says I can't Override that method.

What are you using? SimpleGame? Then override simpleUpdate().

sould I remove the parameters of update ()?

If yes, what do I put in the the arguments for the methods on update() ?

I cannot help you when I dont know what you are doing. Please post your java file here using code tags.

My code:


import com.bulletphysics.collision.shapes.CollisionShape;
import com.jme.app.SimpleGame;
import com.jme.math.Vector3f;
import com.jme.scene.shape.Box;
import com.jme.scene.shape.Sphere;
import com.jmex.jbullet.PhysicsSpace;
import com.jmex.jbullet.nodes.PhysicsNode;

/**
 *
 * @author Gustavo Borba - March, 17th of 2010
 */

public class prjNukeIt extends SimpleGame {

    PhysicsSpace pSpace = PhysicsSpace.getPhysicsSpace();
   
    public static void main(String[] args) {
        prjNukeIt app = new prjNukeIt();
        app.setConfigShowMode(ConfigShowMode.AlwaysShow,
            prjNukeIt.class.getClassLoader().getResource("logo.png"));
        app.start();
    }

    protected void simpleInitGame() {
        //Create a jme sphere
        Sphere sphere = new Sphere("physicssphere",16,16,1f);

        //Create physics sphere from it
        PhysicsNode physicsSphere=new PhysicsNode(sphere, CollisionShape.ShapeTypes.SPHERE);
        physicsSphere.setLocalTranslation(new Vector3f(3,6,0));

        //Add sphere to jme scenegraph
        getRootNode().attachChild(physicsSphere);
        physicsSphere.updateRenderState();

        //Add sphere to physics space
        pSpace.add(physicsSphere);

        //Add a physics mesh as floor to the world, note that objects with mass=0 are static
        Box box=new Box("physicsfloor",Vector3f.ZERO,100f,0.2f,100f);
        PhysicsNode floor=new PhysicsNode(box, CollisionShape.ShapeTypes.MESH);
        floor.setMass(0);
        floor.setLocalTranslation(new Vector3f(0f,-6,0f));

        //Add floor to jme scenegraph
        getRootNode().attachChild(floor);
        floor.updateRenderState();

        //Add floor to physics space
        pSpace.add(floor);
    }
   
    @Override
    public void update(float tpf) {
        super.update(tpf);
        pSpace.update(tpf);
    }
}



NetBeans Errors Images:

http://img59.imageshack.us/gal.php?g=simpleinitgame3.png

The code below works for me. I fixed the CollisionShape import and added an override for simpleUpdate().


import com.jme.app.SimpleGame;
import com.jme.math.Vector3f;
import com.jme.scene.shape.Box;
import com.jme.scene.shape.Sphere;
import com.jmex.jbullet.PhysicsSpace;
import com.jmex.jbullet.collision.shapes.CollisionShape;
import com.jmex.jbullet.nodes.PhysicsNode;

/**
 *
 * @author Gustavo Borba - March, 17th of 2010
 */

public class prjNukeIt extends SimpleGame {

    PhysicsSpace pSpace = PhysicsSpace.getPhysicsSpace();

    public static void main(String[] args) {
        prjNukeIt app = new prjNukeIt();
        app.setConfigShowMode(ConfigShowMode.AlwaysShow,
            prjNukeIt.class.getClassLoader().getResource("logo.png"));
        app.start();
    }

    protected void simpleInitGame() {
        //Create a jme sphere
        Sphere sphere = new Sphere("physicssphere",16,16,1f);

        //Create physics sphere from it
        PhysicsNode physicsSphere=new PhysicsNode(sphere, CollisionShape.ShapeTypes.SPHERE);
        physicsSphere.setLocalTranslation(new Vector3f(3,6,0));

        //Add sphere to jme scenegraph
        rootNode.attachChild(physicsSphere);
        physicsSphere.updateRenderState();

        //Add sphere to physics space
        pSpace.add(physicsSphere);

        //Add a physics mesh as floor to the world, note that objects with mass=0 are static
        Box box=new Box("physicsfloor",Vector3f.ZERO,100f,0.2f,100f);
        PhysicsNode floor=new PhysicsNode(box, CollisionShape.ShapeTypes.MESH);
        floor.setMass(0);
        floor.setLocalTranslation(new Vector3f(0f,-6,0f));

        //Add floor to jme scenegraph
        rootNode.attachChild(floor);
        floor.updateRenderState();

        //Add floor to physics space
        pSpace.add(floor);
    }

    @Override
    public void simpleUpdate() {
        pSpace.update(tpf);
    }
}


Thanks, now all works perfectly.