The code below creates a simple static surface so that I can test controls however for some odd reason when the character gamestate is initated it bounces high off the floor even if i add
staticNode.setMateral(Material.CONCRETE) in the below class and a similar method in the charactertype class can anyone explain?
package com.tps1.lvlLoader;
import java.io.IOException;
import java.util.concurrent.Callable;
import trb.jme.imaging.TextureLoader;
import trb.jme.quake3.Quake3Converter;
import trb.jme.quake3.Quake3Loader;
import com.jme.bounding.BoundingBox;
import com.jme.input.FirstPersonHandler;
import com.jme.input.InputHandler;
import com.jme.light.PointLight;
import com.jme.math.Vector3f;
import com.jme.renderer.Camera;
import com.jme.renderer.ColorRGBA;
import com.jme.scene.Node;
import com.jme.scene.shape.Box;
import com.jme.scene.state.CullState;
import com.jme.scene.state.LightState;
import com.jme.scene.state.ZBufferState;
import com.jme.system.DisplaySystem;
import com.jme.util.GameTaskQueueManager;
import com.jmex.game.StandardGame;
import com.jmex.game.state.GameState;
import com.jmex.game.state.GameStateManager;
import com.jmex.physics.DynamicPhysicsNode;
import com.jmex.physics.StaticPhysicsNode;
import com.tps1.GameState.Charactertype;
import com.tps1.GameState.DefineGameState;
import com.tps1.GameState.SkyBoxManager.SkyBoxGameState;
import com.tps1.util.ErrorHandler;
public class CopyOfCopyOflevelTester extends GameState {
Quake3Converter converter;
Vector3f eyePos = new Vector3f();
//private String name;
public Node rootNode;
private Camera cam;
private DisplaySystem display;
InputHandler input;
public CopyOfCopyOflevelTester(int act, int scene, DefineGameState base){
name="act:"+act+"-scene:"+scene;
rootNode = new Node(name);
cam = base.getCamera();
display = base.getDisplay();
initLevel(base);
base.getRootNode().attachChild(rootNode);
input = new FirstPersonHandler(cam, 8, 1);
GameStateManager.getInstance().attachChild(this);
}
protected void initLevel(DefineGameState base) {
initSetup();
// first we will create the floor
// as the floor can't move we create a _static_ physics node
StaticPhysicsNode staticNode = base.getPhysicsSpace().createStaticNode();
// attach the node to the root node to have it updated each frame
rootNode.attachChild( staticNode );
// now we do not create a collision geometry but a visual box
final Box visualFloorBox = new Box( "floor", new Vector3f(), 22, 0.25f, 22 );
// 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
staticNode.attachChild( visualFloorBox );
// now we let jME Physics 2 generate the collision geometry for our box
staticNode.setModelBound(new BoundingBox());
staticNode.updateModelBound();
staticNode.generatePhysicsGeometry();
rootNode.updateGeometricState(0, true);
rootNode.updateWorldBound();
rootNode.updateRenderState();
}
private void initSetup(){
display.getRenderer().getQueue().setTwoPassTransparency(false);
cam.setFrame(new Vector3f(-14, 1.5f, -2.5f), new Vector3f(0, 0, 1), new Vector3f(0, 1, 0), new Vector3f(-1, 0, 0));
cam.update();
CullState cullState = display.getRenderer().createCullState();
cullState.setCullFace(CullState.Face.Back);
rootNode.setRenderState(cullState);
/**
ZBufferState buf = display.getRenderer().createZBufferState();
buf.setEnabled(true);
buf.setFunction(ZBufferState.TestFunction.LessThanOrEqualTo);
rootNode.setRenderState(buf);
*/
//Sets up lighting
final PointLight light = new PointLight();
light.setDiffuse(new ColorRGBA(0.75f, 0.75f, 0.75f, 0.75f));
light.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
light.setLocation(new Vector3f(100, 100, 100));
light.setEnabled(true);
final LightState lightState = display.getRenderer().createLightState();
lightState.setEnabled(true);
lightState.attach(light);
rootNode.setRenderState(lightState);
}
@Override
public void update(float tpf) {
input.update(tpf);
}
@Override
public final void cleanup(){ // TODO Auto-generated method stub
}
@Override
public final void render(float tpf) { // TODO Auto-generated method stub
}
public static void main(String[] args){
StandardGame standardGame = new StandardGame("GameControl", StandardGame.GameType.GRAPHICAL, null);
standardGame.start();
final DefineGameState base = new DefineGameState("base");
base.setActive(true);
try {
//SkyBoxGameState.Manager().setActive(true);
CopyOfCopyOflevelTester nex = new CopyOfCopyOflevelTester(0,0, base);
nex.setActive(true);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Charactertype Avenger = new Charactertype("ninja",base);
Avenger.setActive(true);
// Avenger.getRootNode().getLocalTranslation().set(345f, 34f, 34f);
}
}