2
0
Эх сурвалжийг харах

Fixed deprecated gravity and jump methods.

mitm 7 жил өмнө
parent
commit
db496d2b60

+ 21 - 21
src/docs/asciidoc/jme3/advanced/terrain_collision.adoc

@@ -1,6 +1,6 @@
 = terrain_collision
-:author: 
-:revnumber: 
+:author:
+:revnumber:
 :revdate: 2016/03/17 20:48
 :keywords: terrain, collision
 :relfileprefix: ../../
@@ -12,7 +12,7 @@ ifdef::env-github,env-browser[:outfilesuffix: .adoc]
 
 == Terrain Collision
 
-This tutorial expands the HelloTerrain tutorial and makes the terrain solid. You combine what you learned in <<jme3/beginner/hello_terrain#,Hello Terrain>> and <<jme3/beginner/hello_collision#,Hello Collision>> and add a CollisionShape to the terrain. The terrain's CollisionShape lets the first-person player (who is also a CollisionShape) collide with the terrain, i.e. walk on it and stand on it. 
+This tutorial expands the HelloTerrain tutorial and makes the terrain solid. You combine what you learned in <<jme3/beginner/hello_terrain#,Hello Terrain>> and <<jme3/beginner/hello_collision#,Hello Collision>> and add a CollisionShape to the terrain. The terrain's CollisionShape lets the first-person player (who is also a CollisionShape) collide with the terrain, i.e. walk on it and stand on it.
 
 
 == Sample Code
@@ -46,7 +46,7 @@ import java.util.List;
 import jme3tools.converters.ImageToAwt;
 
 /**
- * This demo shows a terrain with collision detection, 
+ * This demo shows a terrain with collision detection,
  * that you can walk around in with a first-person perspective.
  * This code combines HelloCollision and HelloTerrain.
  */
@@ -71,14 +71,14 @@ public class HelloTerrainCollision extends SimpleApplication
     /** Set up Physics */
     bulletAppState = new BulletAppState();
     stateManager.attach(bulletAppState);
-    //Uncomment for debugging. 
+    //Uncomment for debugging.
     //bulletAppState.setDebugEnabled(true);
-    
+
     flyCam.setMoveSpeed(100);
     setUpKeys();
 
     /** 1. Create terrain material and load four textures into it. */
-    mat_terrain = new Material(assetManager, 
+    mat_terrain = new Material(assetManager,
             "Common/MatDefs/Terrain/Terrain.j3md");
 
     /** 1.1) Add ALPHA map (for red-blue-green coded splat textures) */
@@ -113,7 +113,7 @@ public class HelloTerrainCollision extends SimpleApplication
     heightmap = new ImageBasedHeightMap(heightMapImage.getImage());
     heightmap.load();
 
-    /** 3. We have prepared material and heightmap. 
+    /** 3. We have prepared material and heightmap.
      * Now we create the actual terrain:
      * 3.1) Create a TerrainQuad and name it "my terrain".
      * 3.2) A good value for terrain tiles is 64x64 -- so we supply 64+1=65.
@@ -134,12 +134,12 @@ public class HelloTerrainCollision extends SimpleApplication
     cameras.add(getCamera());
     TerrainLodControl control = new TerrainLodControl(terrain, cameras);
     terrain.addControl(control);
-    
-    /** 6. Add physics: */ 
-    // We set up collision detection for the scene by creating a static 
+
+    /** 6. Add physics: */
+    // We set up collision detection for the scene by creating a static
     RigidBodyControl with mass zero.*/
     terrain.addControl(new RigidBodyControl(0));
-    
+
     // We set up collision detection for the player by creating
     // a capsule collision shape and a CharacterControl.
     // The CharacterControl offers extra settings for
@@ -149,9 +149,9 @@ public class HelloTerrainCollision extends SimpleApplication
     player = new CharacterControl(capsuleShape, 0.05f);
     player.setJumpSpeed(20);
     player.setFallSpeed(30);
-    player.setGravity(30);
+    player.setGravity(new Vector3f(0,-30,0));
     player.setPhysicsLocation(new Vector3f(-10, 10, 10));
- 
+
     // We attach the scene and the player to the rootnode and the physics space,
     // to make them appear in the game world.
     bulletAppState.getPhysicsSpace().add(terrain);
@@ -185,7 +185,7 @@ public class HelloTerrainCollision extends SimpleApplication
     } else if (binding.equals("Down")) {
       if (value) { down = true; } else { down = false; }
     } else if (binding.equals("Jump")) {
-      player.jump();
+      player.jump(new Vector3f(0,10,0));
     }
   }
 
@@ -211,7 +211,7 @@ public class HelloTerrainCollision extends SimpleApplication
 }
 ----
 
-To try this code, create a `menu:New Project[JME3 > BasicGame]` using the default settings. Paste the sample code over the pregenerated Main.java class. Change the package to '`mygame`' if necessary. Open the `menu:File[Project Properties > Libraries]` and add the `jme3-test-data` library to make certain you have all the files. 
+To try this code, create a `menu:New Project[JME3 > BasicGame]` using the default settings. Paste the sample code over the pregenerated Main.java class. Change the package to '`mygame`' if necessary. Open the `menu:File[Project Properties > Libraries]` and add the `jme3-test-data` library to make certain you have all the files.
 
 Compile and run the code. You should see a terrain. You can use the WASD keys and the mouse to run up and down the hills.
 
@@ -224,7 +224,7 @@ Compile and run the code. You should see a terrain. You can use the WASD keys an
 Read <<jme3/beginner/hello_terrain#,Hello Terrain>> for details of the following parts that we reuse:
 
 .  The `AbstractHeightMap` is an efficient way to describe the shape of the terrain.
-.  The `Terrain.j3md`-based Material and its texture layers let you colorize rocky mountain, grassy valleys, and a paved path criss-crossing over the landscape. 
+.  The `Terrain.j3md`-based Material and its texture layers let you colorize rocky mountain, grassy valleys, and a paved path criss-crossing over the landscape.
 .  The TerrainQuad is the finished `terrain` Spatial that you attach to the rootNode.
 
 
@@ -235,7 +235,7 @@ Read <<jme3/beginner/hello_collision#,Hello Collision>> for details of the follo
 .  The `BulletAppState` lines activate physics.
 .  The `ActionListener` (`onAction()`) lets you reconfigure the input handling for the first-person player, so it takes collision detection into account.
 .  The custom `setUpKeys()` method loads your reconfigured input handlers. They now don't just walk blindly, but calculate the `walkDirection` vector that we need for collision detection.
-.  `simpleUpdate()` uses the `walkDirection` vector and makes the character walk, while taking obstacles and solid walls/floor into account. 
+.  `simpleUpdate()` uses the `walkDirection` vector and makes the character walk, while taking obstacles and solid walls/floor into account.
 
 [source,java]
 ----
@@ -250,13 +250,13 @@ player.setWalkDirection(walkDirection);
 
 Here are the changed parts to combine the two:
 
-.  You create a static (zero-mass) RigidBodyControl. 
+.  You create a static (zero-mass) RigidBodyControl.
 .  Add the control to the `terrain` to make it physical.
 
 [source,java]
 ----
-/** 6. Add physics: */ 
-    terrain.addControl(new RigidBodyControl(0));  
+/** 6. Add physics: */
+    terrain.addControl(new RigidBodyControl(0));
 
 ----