Shoot arrow/bullet with collusion detection

Hey guys,

me again xD



I believe, I think much too complicated. I want to fire simply only one arrow of the focal point of the camera to a certain point. For example, a NPC or something. Here is a little picture, in which I sketched the project:







[java]public class Arrow extends Geometry {

public Vector3f dest;

public Vector3f speed = new Vector3f(.00002f,.00002f,.00002f);

public int ttl = 200000; //Time to life



public Arrow() {

super(“Arrow”, Toolset.arrow);

this.setMaterial(Toolset.material[Toolset.BLUE]);

init();

}



public void move() {

this.setLocalTranslation(this.getLocalTranslation().addLocal(this.dest.mult(this.speed.add(this.getLocalScale()))));

this.ttl -= 1;

if(this.ttl == 0) {

init();

}

}



private void init() {

this.dest = new Vector3f(Toolset.OUT);

this.setLocalTranslation(Toolset.OUT);

this.ttl = 40;

}

}[/java]



My problem is the following:


  • The rate of the arrow depends on the FPS number. If the FPS is high, you hardly see the arrow, is the FPS low, the arrow is too slow.

  • Which class is suitable for an arrow, Geometry, PhysicsNode, PhysicsCharacterNode, Spatial, Particle?



I hope you can help me!

Thanks!

final

or you calculate with the tpf, but I suggest making them physic as well ( you get gravity influrence also that way, and bouncing arrows(hl2 crossbow)

You should use physics and just set a linearVelocity to your arrow. Physics movements are framerate independent



Look at the TestWalkingChar example, and the shootBullet method in particular

If you call your move() method every frame, then the more frames there are, the faster the arrow will move.

You need to pass the TPF value you get in simpleUpdate() to the move() method and multiply it by the velocity to get framerate-independent movement.