it doesn't work and the bullet starts anywhere on a circle with the radius 0.5 around the center (crosshair)
depending on the camera movement
So I changed the FireBullet class to this: (to make the bullet rotate with my camera movements)
/** Move bullet to the camera location */
//bullet.setLocalTranslation(new Vector3f(cam.getLocation())); //<- old one
You can make use of the scenegraph here; if you have a player-node, you can attach a gun to it which will make it turn and twist with the player. Then you just shoot your bullets in the gun's direction!
for the other things,
well I reused the example in helloIntersection, which creates a new bullet every time the perfomAction method is called...
yes it would be better to reuse the bullets...
guess i'll look at the furballz code then
But in the one you commented out, you were using the "new" keyword. That tells Java you want to allocate more memory for, in your case, a brand new Vector3f. It's usually better to have your update logic clean of "news"
I thought that was what was reffered to as a "leak" in Java (?).
Not exactly. A leak in Java would mean that some memory cannot be reclaimed (objects garbage collected). e.g. a static reference to all created spatials...
Creating many new vectors and throwing them away only causes the application to hang quite often (when the garbage collector kicks in) the actual memory usage does not climb up that badly.
Not exactly. A leak in Java would mean that some memory cannot be reclaimed (objects garbage collected). e.g. a static reference to all created spatials...
You're right -- that's a better definition!
Fly: yes, I guess, that pseudo-code is a little hard to get :)
Though… I hope that's not pasted from your update logic, as "new Vector3f(gunWorldPos)" would prove a memory-leak. Better to use bullet.getLocalTranslation.set(gunWorldPos).
Also, why are you setting a render state there? Such things should only be done when initializing the bullets, and the code you pasted seemed to come from a fire event of some sort.
The proper way to handle bullets and such is to store sets of them in pools, so that you can just reuse them when needed. It would surprise me if Furballs isn't doing this, so a tip is to poke around some in that code (if you're not already doing this (!)).