So Today I tried to implement some physics stuff into the game. Now my guy/camera won’t move. player.setwalkdirection dosen’t seem to do anything. Here is my code. http://pastebin.com/A01X42ge Thanks for helping.
Please someone explain to me why some of you guys use Pastebin? What’s the benefit? Because honestly I don’t see one reason. None.
Why not simply paste that code in a JAVA tag? It’ll stay formatted and even color coded.
Sorry I didn’t see a java tag and I am new to the forums. Maybe this will work? [java]/*
package net.gyroninja.Cavein;
import com.jme3.app.Application;
import com.jme3.app.SimpleApplication;
import com.jme3.app.state.AppStateManager;
import com.jme3.asset.AssetManager;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.collision.shapes.SphereCollisionShape;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.bullet.objects.PhysicsCharacter;
import com.jme3.bullet.util.CollisionShapeFactory;
import com.jme3.input.InputManager;
import com.jme3.input.KeyInput;
import com.jme3.input.controls.ActionListener;
import com.jme3.input.controls.KeyTrigger;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.Vector3f;
import com.jme3.renderer.Camera;
import com.jme3.renderer.RenderManager;
import com.jme3.renderer.ViewPort;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
/**
*
-
@author gyroninja
*/
public class CaveGameState extends BulletAppState implements ActionListener{
boolean left = false, right = false, up = false, down = false;
public SimpleApplication app;
Node rootNode;
AssetManager assetManager;
AppStateManager stateManager;
InputManager inputManager;
ViewPort viewPort;
BulletAppState bullet;
Spatial Level;
Material mat;
DirectionalLight sun;
Camera cam;
PhysicsCharacter player;
Vector3f walkDirection = new Vector3f();
@Override
public void initialize(AppStateManager stateManager, Application app) {
super.initialize(stateManager, app);
this.app = (SimpleApplication) app;
this.rootNode = this.app.getRootNode();
this.assetManager = this.app.getAssetManager();
this.stateManager = this.app.getStateManager();
this.inputManager = this.app.getInputManager();
this.viewPort = this.app.getViewPort();
this.bullet = this.stateManager.getState(BulletAppState.class);
this.cam = app.getCamera();
this.setUpKeys();
Level = assetManager.loadModel("Models/cave/cave.j3o");
mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setTexture("ColorMap", assetManager.loadTexture("Models/cave/stone.png"));
Level.setMaterial(mat);
sun = new DirectionalLight();
sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f));
rootNode.attachChild(Level);
rootNode.addLight(sun);
player = new PhysicsCharacter(new SphereCollisionShape(5), .01f);
player.setJumpSpeed(20);
player.setFallSpeed(30);
player.setGravity(30);
player.setPhysicsLocation(new Vector3f(10, 10, 10));
RigidBodyControl landscape = new RigidBodyControl(CollisionShapeFactory.createMeshShape(Level), 0);
Level.addControl(landscape);
// this.getPhysicsSpace().add(Level);
this.getPhysicsSpace().add(player);
this.getPhysicsSpace().enableDebug(assetManager);
}
@Override
public void cleanup() {
}
@Override
public void setEnabled(boolean enabled) {
}
@Override
public void update(float tpf) {
Vector3f camDir = cam.getDirection().clone().multLocal(0.6f);
Vector3f camLeft = cam.getLeft().clone().multLocal(0.4f);
walkDirection.set(0, 0, 0);
if (left) {
walkDirection.addLocal(camLeft);
}
if (right) {
walkDirection.addLocal(camLeft.negate());
}
if (up) {
walkDirection.addLocal(camDir);
}
if (down) {
walkDirection.addLocal(camDir.negate());
}
player.setWalkDirection(walkDirection);
System.out.println(player.getWalkDirection());
cam.setLocation(player.getPhysicsLocation());
System.out.println(cam.getLocation());
}
@Override
public void render(RenderManager rm) {
}
public void setUpKeys() {
inputManager.addMapping("Left", new KeyTrigger(KeyInput.KEY_A));
inputManager.addMapping("Right", new KeyTrigger(KeyInput.KEY_D));
inputManager.addMapping("Up", new KeyTrigger(KeyInput.KEY_W));
inputManager.addMapping("Down", new KeyTrigger(KeyInput.KEY_S));
inputManager.addMapping("Jump", new KeyTrigger(KeyInput.KEY_SPACE));
inputManager.addListener(this, "Left");
inputManager.addListener(this, "Right");
inputManager.addListener(this, "Up");
inputManager.addListener(this, "Down");
inputManager.addListener(this, "Jump");
}
@Override
public void onAction(String binding, boolean value, float tpf) {
if (binding.equals("Left")) {
left = value;
}
if (binding.equals("Right")) {
right = value;
}
if (binding.equals("Up")) {
up = value;
}
if (binding.equals("Down")) {
down = value;
}
if (binding.equals("Jump")) {
player.jump();
}
}
}[/java]