Hello i really need help about getPhysicsSpace()
i’m still beginner and i don’t know what should i do because i just copy some code
package mygame;
import com.jme3.animation.AnimChannel;
import com.jme3.animation.AnimControl;
import com.jme3.animation.AnimEventListener;
import com.jme3.animation.LoopMode;
import com.jme3.app.SimpleApplication;
import com.jme3.app.state.AppState;
import com.jme3.bullet.BulletAppState;
import com.jme3.bullet.PhysicsSpace;
import com.jme3.bullet.collision.shapes.CapsuleCollisionShape;
import com.jme3.bullet.control.CharacterControl;
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.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.bullet.control.RigidBodyControl;
import com.jme3.input.ChaseCamera;
/**
* test
* @author normenhansen
*/
public class Main extends SimpleApplication implements AnimEventListener{
private Spatial sceneModel;
protected Vector3f V = new Vector3f(0, 0, 0);
private AnimChannel animchannel,animchannel2;
private AnimControl anim;
private CharacterControl character;
private Node SinbadNode;
private ChaseCamera chaseCam;
private RigidBodyControl landscape;
boolean isRun = false;
Vector3f walkDirection = new Vector3f();
public static void main(String[] args) {
Main app = new Main();
app.start();
}
ActionListener action = new ActionListener(){
public void onAction(String name, boolean isPressed, float tpf)
{
if(isRun)
{
if(name.equals("Top"))
{
SinbadNode.getLocalTranslation();
animchannel.setAnim("RunTop");
animchannel2.setAnim("RunBase");
SinbadNode.move(0, 0, 15*speed);
isRun = true;
}
if(!isPressed)
{
animchannel.setAnim("IdleTop");
animchannel.setAnim("IdleBase");
isRun = false;
}
}
}
};
private PhysicsSpace getPhysicsSpace() {
return BulletAppState.getPhysicsSpace();
}
public void initKeys()
{
inputManager.addMapping("Up", new KeyTrigger(KeyInput.KEY_W));
inputManager.addMapping("Down", new KeyTrigger(KeyInput.KEY_S));
inputManager.addMapping("Left", new KeyTrigger(KeyInput.KEY_D));
inputManager.addMapping("Right", new KeyTrigger(KeyInput.KEY_A));
inputManager.addListener(actionlistener, new String[]{"Pause"});
inputManager.addListener(action, new String[]{"Up","Down","Left","Right"});
};
@Override
public void simpleInitApp(){
setDisplayFps(false);
setDisplayStatView(false);
this.inputManager.clearMappings();
Vector3f camDir = cam.getDirection().clone().multLocal(0.1f);
Vector3f camLeft = cam.getLeft().clone().multLocal(0.1f);
//TERRAIN
viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 1f));
sceneModel = assetManager.loadModel("Scenes/Scene.j3o");
rootNode.attachChild(sceneModel);
flyCam.setMoveSpeed(30);
flyCam.setEnabled(false);
AppState bulletAppState = new BulletAppState();
stateManager.attach(bulletAppState);
anim = SinbadNode.getControl(AnimControl.class);
//anim.addListener(this);
animchannel = anim.createChannel();
animchannel2 = anim.createChannel();
//animchannel.setAnim("IdleBase");
//animchannel2.setAnim("IdleTop");
chaseCam = new ChaseCamera(cam, SinbadNode, inputManager);
rootNode.addLight(new DirectionalLight());
character.setWalkDirection(walkDirection);
initKeys();
}
@Override
public void simpleUpdate(float tpf)
{
}
@Override
public void simpleRender(RenderManager rm) {
//TODO: add render code
}
private ActionListener actionlistener = new ActionListener() {
public void onAction(String name, boolean isPressed, float tpf)
{
if(name.equals("Run") && !isPressed)
{
if (!animchannel.getAnimationName().equals("Run")) {
animchannel.setAnim("Stand", 0.50f);
animchannel.setLoopMode(LoopMode.Cycle);
}
}
}
};
public void initChar()
{
CapsuleCollisionShape capsule = new CapsuleCollisionShape(3f, 4f);
character = new CharacterControl(capsule, 0.01f);
SinbadNode = new Node("Sinbad Node");
SinbadNode = (Node)assetManager.loadModel("Models/Sinbad/Sinbad.mesh.xml");
SinbadNode.addControl(character);
rootNode.attachChild(SinbadNode);
getPhysicsSpace().add(character);
}
public void onAnimCycleDone(AnimControl control, AnimChannel channel, String animName)
{
if(animName.equals("IdleBase"))
{
channel.setSpeed(2f);
channel.setAnim("Dance");
}
}
public void onAnimChange(AnimControl control, AnimChannel channel, String animName) {
}
}