Hey,
I tried out the Hello Physics tutorial where you shoot cannonballs at the brick wall.
Now I tried to make a test program of my own.
My goal is to put the camera at the position of my PhysicsCharacterNode and to be able to shoot cannonballs.
I tried this but I failed to get the correct behavior.
When I use cam without modifying it, it works fine, I set some velocity cannonballNode.setLinearVelocity(cam.getDirection().mult(500f)); to the cannonball and I am alright.
But now, as soon as I put cam.setLocation(player.getLocalTranslation()); in simpleUpdate method (where player is a PhysicsCharacterNode) the behavior changes.
I start the game, when I shoot in front of me the ball flies at the direction of my crosshair, when I turn around and shoot, cannon ball still comes out, but behind me and I get moved forward a little (that may be mass, but it doesn’t happen shooting in the other side)!
So the more I turn the more wrong it goes.
private PhysicsCharacterNode player;
simpleInitApp
player = new PhysicsCharacterNode(new CapsuleCollisionShape(1.5f, 6f, 1), .5f);
player.setJumpSpeed(40);
player.setFallSpeed(80);
player.setGravity(80);
player.setLocalTranslation(new Vector3f(0, 210, 0));
rootNode.attachChild(player);
bulletAppState.getPhysicsSpace().add(player);
simpleUpdate
cam.setLocation(player.getLocalTranslation());
onAction shoot
PhysicsNode cannonballNode = new PhysicsNode(
fire, // geometry
spearCollisionShape, // collision shape
5.0f);
cannonballNode.setLocalTranslation(cam.getLocation());
rootNode.attachChild(cannonballNode);
bulletAppState.getPhysicsSpace().add(cannonballNode);
cannonballNode.setLinearVelocity(cam.getDirection().mult(500f));
As I said, without cam.setLocation(player.getLocalTranslation()); I get the correct behavior but I use the regular flyby mode. But as soon as I add this line it changes.
Does anyone know whats up?