Hi everyone,
I have another annoying problem which I cant solve. My spaceship fires bullets coming from the ship. This goes fine when I simply fly straight forward when I start the program. I dont move anywhere else, just straight forward. This can be seen from the image:
There are some bullets in the far distance. That works fine.
But whenever I move the ship and I fire, the bullets first seem to be ok, coming from the ship. But then whenever I fire they simply seem to be moving further to the right and not into the direction the ship is pointing. Basically, the bullets dont go into the right direction :S
Here is the code that makes the bullet, and the bulletmover.
Fire a bullet!
public void fire(){
model = new Sphere("bullet" + numBullets++, 8, 8, .25f);
model.setModelBound(new BoundingBox());
model.updateModelBound();
model.setLocalTranslation(new Vector3f(camera.getDirection()));
model.updateGeometricState(0, true);
model.addController(new WeaponMover(this,model,new Vector3f(ship.getModel().getWorldTranslation())));
this.attachChild(model);
model.updateRenderState();
}
Move the bullet:
public void update(float time){
lifeTime-=time;
if (lifeTime < 0) {
weapon.detachChild(this.bullet);
weapon.removeController(this);
return;
}
Vector3f currPos = this.bullet.getLocalTranslation();
currPos.addLocal(direction.mult(time * speed));
System.out.println(direction + " " + time + " " + speed);
this.bullet.setLocalTranslation(currPos);
}
Thanks for the furball code btw :)
I think the problem lies with the getMode.getWorldTranslation. But the model is pointing forward, just like in the image or another direction. And I cant use the camera.getDirection, this lets the bullets also behave irratically.
Regards,
Frank