Hi
I'm having trouble inserting static objects to the world, to test with my character, it crosses into the box.
my class:
package events;
import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingBox;
import com.jme.input.InputHandler;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.input.action.InputAction;
import com.jme.input.action.InputActionEvent;
import com.jme.intersection.CollisionResults;
import com.jme.math.Vector3f;
import com.jme.scene.Geometry;
import com.jme.scene.Node;
import com.jme.scene.Spatial;
import com.jme.scene.shape.Box;
import com.jme.scene.shape.Sphere;
import com.jmex.jbullet.PhysicsSpace;
import com.jmex.jbullet.collision.CollisionEvent;
import com.jmex.jbullet.collision.CollisionListener;
import com.jmex.jbullet.collision.shapes.BoxCollisionShape;
import com.jmex.jbullet.collision.shapes.CollisionShape;
import com.jmex.jbullet.collision.shapes.MeshCollisionShape;
import com.jmex.jbullet.nodes.PhysicsCharacterNode;
import com.jmex.jbullet.nodes.PhysicsNode;
public class TestEvent extends SimpleGame {
PhysicsSpace space = PhysicsSpace.getPhysicsSpace();
private static PhysicsNode sensor2;
private static PhysicsCharacterNode pcn;
private static Vector3f walkDirection = new Vector3f();
/**
* @param args
*/
public static void main(String[] args) {
TestEvent app = new TestEvent();
app.setConfigShowMode(ConfigShowMode.AlwaysShow);
app.start();
}
@Override
protected void simpleInitGame() {
PhysicsNode piso = new PhysicsNode(
new Box("chao", new Vector3f(), new Vector3f(100,1,100)),
CollisionShape.ShapeTypes.MESH,
0);
piso.setLocalTranslation(0,-1,0);
rootNode.attachChild(piso);
piso.updateRenderState();
space.add(piso);
final PhysicsNode sensor = new PhysicsNode(
new Box("sensor", new Vector3f(0,0,0), new Vector3f(10,10,10)),
CollisionShape.ShapeTypes.BOX,
0);
sensor.setLocalTranslation(10f, 0f, 10f);
rootNode.attachChild(sensor);
sensor.updateModelBound();
sensor.updateRenderState();
space.add(sensor);
sensor2 = new PhysicsNode(
new Box("sensor2", Vector3f.ZERO, new Vector3f(10,10,10)),
CollisionShape.ShapeTypes.MESH,
0f);
sensor2.setLocalTranslation(new Vector3f(30f, -1f, 10f));
rootNode.attachChild(sensor2);
sensor2.updateModelBound();
sensor2.updateRenderState();
space.add(sensor2);
pcn = new PhysicsCharacterNode(
new Box("person", new Vector3f(0,0,0),new Vector3f(1,2,1)),
CollisionShape.ShapeTypes.BOX, .1f);
rootNode.attachChild(pcn);
pcn.setLocalTranslation(5, 15, 5);
pcn.updateRenderState();
pcn.setMaxJumpHeight(1f);
space.add(pcn);
final PhysicsNode bola = new PhysicsNode(
new Sphere("bola",new Vector3f(), 10,10, 5f),
CollisionShape.ShapeTypes.SPHERE,0);
bola.setLocalTranslation(50, 0, 50);
final PhysicsNode bola2 = new PhysicsNode(
new Sphere("bola2",new Vector3f(), 10,10, 2f),
CollisionShape.ShapeTypes.SPHERE,0);
rootNode.attachChild(bola2);
bola2.setLocalTranslation(20, 0, 50);
space.add(bola2);
space.addCollisionListener(new CollisionListener() {
@Override
public void collision(CollisionEvent event) {
if (event.getNodeB().equals(bola)) System.out.println("Bola " + event.getAppliedImpulse());
if (event.getNodeB().equals(bola2)) System.out.println("Bola 2 " + event.getAppliedImpulse());
if (event.getNodeB().equals(sensor)) System.out.println("Sensor " + event.getAppliedImpulse());
}
});
KeyBindingManager.getKeyBindingManager().set("cam",
KeyInput.KEY_LCONTROL);
space.add(bola);
rootNode.attachChild(bola);
input.addAction( accelAction, InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_U, InputHandler.AXIS_NONE, false);
input.addAction( brakeAction, InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_J, InputHandler.AXIS_NONE, false);
input.addAction( steerLeftAction, InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_H, InputHandler.AXIS_NONE, false);
input.addAction( steerRightAction, InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_K, InputHandler.AXIS_NONE, false);
input.addAction( spaceAction, InputHandler.DEVICE_KEYBOARD, KeyInput.KEY_SPACE, InputHandler.AXIS_NONE, false);
}
private static InputAction accelAction = new InputAction() {
public void performAction( InputActionEvent evt ) {
if(evt.getTriggerPressed()){
walkDirection.addLocal(new Vector3f(0,0,-.1f));
}
else{
walkDirection.addLocal(new Vector3f(0,0,.1f));
}
pcn.setWalkDirection(walkDirection);
}
};
private static InputAction brakeAction = new InputAction() {
public void performAction( InputActionEvent evt ) {
if(evt.getTriggerPressed()){
walkDirection.addLocal(new Vector3f(0,0,.1f));
}
else{
walkDirection.addLocal(new Vector3f(0,0,-.1f));
}
pcn.setWalkDirection(walkDirection);
}
};
private static InputAction steerLeftAction = new InputAction() {
public void performAction( InputActionEvent evt ) {
if(evt.getTriggerPressed()){
walkDirection.addLocal(new Vector3f(-.1f,0,0));
}
else{
walkDirection.addLocal(new Vector3f(.1f,0,0));
}
pcn.setWalkDirection(walkDirection);
}
};
private static InputAction steerRightAction = new InputAction() {
public void performAction( InputActionEvent evt ) {
if(evt.getTriggerPressed()){
walkDirection.addLocal(new Vector3f(.1f,0,0));
}
else{
walkDirection.addLocal(new Vector3f(-.1f,0,0));
}
pcn.setWalkDirection(walkDirection);
}
};
private static InputAction spaceAction = new InputAction() {
public void performAction( InputActionEvent evt ) {
if(evt.getTriggerPressed()){
pcn.jump();
}
else{
}
}
};
@Override
protected void simpleUpdate() {
// TODO Auto-generated method stub
super.simpleUpdate();
space.update(tpf);
if (KeyBindingManager.getKeyBindingManager().isValidCommand(
"cam", true)) {
System.out.println(cam.getLocation());
}
}
}