Ok nymon, I appreciate your willingness to help ^^
import java.net.URL;
import lts.core.objects.LTSGameObject;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.math.Vector3f;
import com.jme.renderer.Renderer;
import com.jme.scene.shape.Box;
import com.jmex.physics.CollisionGroup;
import com.jmex.physics.DynamicPhysicsNode;
import com.jmex.physics.PhysicsCollisionGeometry;
import com.jmex.physics.StaticPhysicsNode;
import com.jmex.physics.contact.MutableContactInfo;
import com.jmex.physics.material.Material;
import com.jmex.physics.util.SimplePhysicsGame;
public class SimpleGamePhysikTestAlex extends SimplePhysicsGame{
//Static Physic nodes
StaticPhysicsNode floor;
//Dynamic Physic Nodes
DynamicPhysicsNode tank;
Box b;
//PhysicsCollisionGeometry
private PhysicsCollisionGeometry playerLeftPart;
private PhysicsCollisionGeometry playerRightPart;
StaticPhysicsNode boxNode;
//CollisionGroups
CollisionGroup cgFloor;
CollisionGroup cgTank;
//GameElements
LTSGameObject[][] gameObjects;
private int gameRows;
//Others
private Renderer renderer;
private void initPlayer() {
tank = getPhysicsSpace().createDynamicNode();
rootNode.attachChild(tank);
// Tank down part
tank.attachChild( new Box( "player", new Vector3f(), 0.35f, 0.3f, 0.3f ) );
playerLeftPart = tank.createBox( "left" );
playerLeftPart.getLocalTranslation().set( 0, 0, 0.15f );
playerLeftPart.getLocalScale().set( 0.7f, 0.6f, 0.3f );
playerRightPart = tank.createBox( "right" );
playerRightPart.getLocalTranslation().set( 0, 0, -0.15f );
playerRightPart.getLocalScale().set( 0.7f, 0.6f, 0.3f );
tank.getLocalTranslation().set( 6, 0.5f, 5 );
// Rotator and aim
// Collision Group
cgTank = getPhysicsSpace().createCollisionGroup("tank");
tank.setCollisionGroup(cgTank);
cgTank.collidesWith(cgTank, false);
cgFloor.collidesWith(cgTank, true);
// MAss
tank.setMass(25.5f);
playerLeftPart.setMaterial( new Material( "player material left" ) );
playerRightPart.setMaterial( new Material( "player material right" ) );
MutableContactInfo info = new MutableContactInfo();
{
info.setMu( 1 );
info.setBounce( 0.4f );
info.setMinimumBounceVelocity( 1f );
info.setMuOrthogonal( 0.01f );
}
playerLeftPart.getMaterial().putContactHandlingDetails( null, info );
playerRightPart.getMaterial().putContactHandlingDetails( null, info );
}
public static void main(String[] args) {
// TODO Auto-generated method stub
SimpleGamePhysikTestAlex t = new SimpleGamePhysikTestAlex();
t.start();
}
@Override
protected void simpleInitGame() {
renderer = display.getRenderer();
//initmap("Map1x8.lts");
createFloor();
initPlayer();
// LTSHandleConfig ltsHandleConfig = new LTSHandleConfig();
// ltsHandleConfig.loadConfig();
KeyBindingManager.getKeyBindingManager().set("pause", KeyInput.KEY_P);
KeyBindingManager.getKeyBindingManager().set("exit", KeyInput.KEY_ESCAPE);
KeyBindingManager.getKeyBindingManager().set("vor", KeyInput.KEY_1);
KeyBindingManager.getKeyBindingManager().set("back", KeyInput.KEY_2);
KeyBindingManager.getKeyBindingManager().set("left", KeyInput.KEY_3);
KeyBindingManager.getKeyBindingManager().set("right", KeyInput.KEY_4);
KeyBindingManager.getKeyBindingManager().set("removeBox", KeyInput.KEY_5);
showPhysics = true;
//pause = true;
}
public void releaseTankSpeed()
{
Vector3f direction = new Vector3f( 0, 0, 0 );
playerLeftPart.getMaterial().setSurfaceMotion( direction );
playerRightPart.getMaterial().setSurfaceMotion( direction );
}
public void moveForward()
{
Vector3f direction;
direction = new Vector3f( 1.5f, 0, 0 );
playerLeftPart.getMaterial().setSurfaceMotion( direction );
playerRightPart.getMaterial().setSurfaceMotion( direction );
}
public void moveBack()
{
Vector3f direction;
direction = new Vector3f( -1.5f, 0, 0 );
playerLeftPart.getMaterial().setSurfaceMotion( direction );
playerRightPart.getMaterial().setSurfaceMotion( direction );
}
public void moveLeft()
{
Vector3f direction;
direction = new Vector3f( -0.25f, 0, 0 );
playerLeftPart.getMaterial().setSurfaceMotion( direction );
direction = new Vector3f( 0.25f, 0, 0 );
playerRightPart.getMaterial().setSurfaceMotion( direction );
}
public void moveRight()
{
Vector3f direction;
direction = new Vector3f( 0.25f, 0, 0 );
playerLeftPart.getMaterial().setSurfaceMotion( direction );
direction = new Vector3f( -0.25f, 0, 0 );
playerRightPart.getMaterial().setSurfaceMotion( direction );
}
@Override protected void simpleUpdate()
{
boolean moved = false;
if (KeyBindingManager.getKeyBindingManager().isValidCommand("vor", true)) {
moved = true;
moveForward();
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand("back", true)) {
moved = true;
moveBack();
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand("right", true)) {
moved = true;
moveRight();
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand("left", true)) {
moved = true;
moveLeft();
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand("removeBox", true)) {
boxNode.detachChild(b);
boxNode.setActive(false);
floor.detachChild(boxNode);
}
if (KeyBindingManager.getKeyBindingManager().isValidCommand("exit", false)) {
this.finish();
//StartGame.bgState.setActive(true);
//StartGame.singlePlayerState.setActive(true);
}
if(!moved)
{
if(playerLeftPart != null)
{
releaseTankSpeed();
}
}
}
private void createFloor() {
URL res = null;
floor = getPhysicsSpace().createStaticNode();
rootNode.attachChild(floor);
final Box visualFloorBox = new Box( "floor", new Vector3f(), 10, 0.25f, 10 );
floor.attachChild( visualFloorBox );
b = new Box("toRemove", new Vector3f(), 1,1,1);
boxNode = getPhysicsSpace().createStaticNode();
boxNode.setName("BoxNode");
boxNode.attachChild(b);
floor.attachChild( boxNode );
b.getLocalTranslation().set(4,0.5f,6);
boxNode.generatePhysicsGeometry();
floor.generatePhysicsGeometry();
cgFloor = getPhysicsSpace().createCollisionGroup("floor");
floor.setCollisionGroup(cgFloor);
}
}
The removal of the box is done in the simple update method. What am I missing?
Some words, what's done in the "game":
There will be two boxes and a floor. One of the boxes is a DynamicPhysicsNode which can be moved by pressing Keys 1, 2, 3 and 4 (not the numpad keys, since I have a laptop^^). The other box is a static element and the dynamic box (our "tank") is able to collide with this one. By pressing now the 5 key, it will be called the setActive-method of the node, where the static box is attached to, then it will be removed from the floor-node. But the tank still collides with the "ghost" box...I have no clue about that...Oo
Regards