Physicsgamestate example + GameControl Basic example

Hello friends,

I wanted to use BasicGameState with PhysicsGameState. I used this examples:

In original PhysicsGameState example is "falling box" above floor, in my program is under a falling left. I don`t understand why. I just put "everything" in  "SnakeGameState extends BasicGameState" constructor.

package pokus1;


public class Main

   public static void main(String [] args)

      // Create and start the OpenGL thread.
      final StandardGame game = new StandardGame("Physics tutorial");

      final SnakeGameState normalGameState = new SnakeGameState();

      // Now let jME know about the game states we've created.


package pokus1;

import com.jme.math.Vector3f;
import com.jme.scene.shape.Box;
import com.jmex.physics.DynamicPhysicsNode;
import com.jmex.physics.StaticPhysicsNode;
import com.jmex.physics.util.states.PhysicsGameState;

public class SnakeGameState extends BasicGameState {

    public SnakeGameState(){
        // Create the PhysicsGameState object. This will track all state related to the physics
        // interactions.
        final PhysicsGameState physicsGameState = new PhysicsGameState("Physics tutorial");


        // first we will create the floor
        // as the floor can't move we create a _static_ physics node
        StaticPhysicsNode staticNode = physicsGameState.getPhysicsSpace().createStaticNode();

        // attach the node to the root node to have it updated each frameit

        // now we do not create a collision geometry but a visual box
        final Box visualFloorBox = new Box("floor", new Vector3f(), 5, 0.25f, 5);
        // note: we have used the constructor (name, center, xExtent, yExtent, zExtent)
        // thus our box is centered at (0,0,0) and has size (10, 0.5f, 10)

        // we have to attach it to our node

        // now we let jME Physics 2 generate the collision geometry for our box

        // second we create a box that should fall down on the floor
        // as the new box should move we create a _dynamic_ physics node
        DynamicPhysicsNode dynamicNode = physicsGameState.getPhysicsSpace().createDynamicNode();

        // again we create a visual box
        final Box visualFallingBox = new Box("falling box", new Vector3f(), 0.5f, 0.5f, 0.5f);
        // note: again we have used the constructor (name, center, xExtent, yExtent, zExtent)
        // thus our box is centered at (0,0,0) and has size (1, 1, 1)
        // the center is really important here because we want the center of the box to lie in the
        // center
        // of the dynamic physics node - which is the center of gravity!

        // attach it to the dynamic node

        // and generate collision geometries again

        // we have to move our dynamic node upwards such that is does not start in but above the
        // floor
        dynamicNode.getLocalTranslation().set(0, 5, 0);
        // note: we do not move the collision geometry but the physics node!

        // now we have visuals for the physics and don't necessarily need to activate the physics
        // debugger
        // though you can do it (V key) to see physics in the app

        // Once all this is set up, we need to update the render state on the root node.




        getRootNode().updateGeometricState(0.0f, true);

helped.  :slight_smile: