Java Code Examples for com.jme3.bullet.control.CharacterControl#setGravity()

The following examples show how to use com.jme3.bullet.control.CharacterControl#setGravity() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HelloCollision.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void simpleInitApp() {
  /** Set up Physics */
  bulletAppState = new BulletAppState();
  stateManager.attach(bulletAppState);
  //bulletAppState.getPhysicsSpace().enableDebug(assetManager);

  // We re-use the flyby camera for rotation, while positioning is handled by physics
  viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 1f));
  flyCam.setMoveSpeed(100);
  setUpKeys();
  setUpLight();

  // We load the scene from the zip file and adjust its size.
  assetManager.registerLocator(
                  "https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/jmonkeyengine/town.zip",
                  HttpZipLocator.class);
  sceneModel = assetManager.loadModel("main.scene");
  sceneModel.setLocalScale(2f);

  // We set up collision detection for the scene by creating a
  // compound collision shape and a static RigidBodyControl with mass zero.
  CollisionShape sceneShape =
          CollisionShapeFactory.createMeshShape(sceneModel);
  landscape = new RigidBodyControl(sceneShape, 0);
  sceneModel.addControl(landscape);

  // We set up collision detection for the player by creating
  // a capsule collision shape and a CharacterControl.
  // The CharacterControl offers extra settings for
  // size, stepheight, jumping, falling, and gravity.
  // We also put the player in its starting position.
  CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1.5f, 6f, 1);
  player = new CharacterControl(capsuleShape, 0.05f);
  player.setJumpSpeed(20);
  player.setFallSpeed(30);
  player.setGravity(30);
  player.setPhysicsLocation(new Vector3f(0, 10, 0));

  // We attach the scene and the player to the rootnode and the physics space,
  // to make them appear in the game world.
  rootNode.attachChild(sceneModel);
  bulletAppState.getPhysicsSpace().add(landscape);
  bulletAppState.getPhysicsSpace().add(player);
}
 
Example 2
Source File: HelloCollision.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void simpleInitApp() {
  /** Set up Physics */
  bulletAppState = new BulletAppState();
  stateManager.attach(bulletAppState);
  //bulletAppState.getPhysicsSpace().enableDebug(assetManager);

  // We re-use the flyby camera for rotation, while positioning is handled by physics
  viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 1f));
  flyCam.setMoveSpeed(100);
  setUpKeys();
  setUpLight();

  // We load the scene from the zip file and adjust its size.
  assetManager.registerLocator("town.zip", ZipLocator.class.getName());
  sceneModel = assetManager.loadModel("main.scene");
  sceneModel.setLocalScale(2f);

  // We set up collision detection for the scene by creating a
  // compound collision shape and a static RigidBodyControl with mass zero.
  CollisionShape sceneShape =
          CollisionShapeFactory.createMeshShape((Node) sceneModel);
  landscape = new RigidBodyControl(sceneShape, 0);
  sceneModel.addControl(landscape);

  // We set up collision detection for the player by creating
  // a capsule collision shape and a CharacterControl.
  // The CharacterControl offers extra settings for
  // size, stepheight, jumping, falling, and gravity.
  // We also put the player in its starting position.
  CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1.5f, 6f, 1);
  player = new CharacterControl(capsuleShape, 0.05f);
  player.setJumpSpeed(20);
  player.setFallSpeed(30);
  player.setGravity(30);
  player.setPhysicsLocation(new Vector3f(0, 10, 0));

  // We attach the scene and the player to the rootnode and the physics space,
  // to make them appear in the game world.
  rootNode.attachChild(sceneModel);
  bulletAppState.getPhysicsSpace().add(landscape);
  bulletAppState.getPhysicsSpace().add(player);
}