Hi, I would like to ask about shooting of NPC. What should I use to get NPC’s shooting (ActionListener, Rays, Controls… Something else…)? I want to show flying bullets (like in old scroll-shooter projects), so bullets are flying Geometries.
This is a concept:
http://imageshack.us/photo/my-images/560/bulleto.jpg/
Uploaded with ImageShack.us
Also, I did a test project (only 2 classes) to have a try it.
ShootBullet.java
[java]
import com.jme3.asset.AssetManager;
import com.jme3.material.Material;
import com.jme3.math.*;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
/**
*
-
@author mifth
/
public class ShootBullet {
Node shotGroup = new Node("shotGroup");
Box box_a = new Box(Vector3f.ZERO, 1, 1, 1);
Spatial charShoot;
Material mat_box;
Geometry bullet;
// ShootTest ast = new ShootTest();
public void shootObj (AssetManager AssetManager) {
// Create a box Geometry
charShoot = new Geometry("Box", box_a);
charShoot.scale(1,1,2);
mat_box = new Material(AssetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat_box.setColor("Color", ColorRGBA.Blue);
charShoot.setMaterial(mat_box);
shotGroup.attachChild(charShoot);
}
void shootBullets (AssetManager AssetManager) {
bullet = new Geometry ("Bullet", box_a);
Material mat_bullet = new Material(AssetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat_bullet.setColor("m_Color", ColorRGBA.Red);
bullet.setMaterial(mat_bullet);
Transform bulletTrans = charShoot.getWorldTransform().setScale(0.5f,0.5f,0.5f);
bullet.setLocalTransform(bulletTrans);
bullet.move(0,0,5f);
shotGroup.attachChild(bullet);
}
void moveBullet (float tpf){
bullet.move(0,0,7ftpf);
}
void rotateObj (float tpf){
charShoot.rotate(0,2ftpf,0);
}
}[/java]
ShootBulletRun.java
[java]
import com.jme3.app.SimpleApplication;
import com.jme3.font.BitmapText;
import com.jme3.math.;
import com.jme3.system.AppSettings;
public class ShootBulletRun extends SimpleApplication {
public static void main(String[] args) {
ShootBulletRun app = new ShootBulletRun();
//set vSinc on to get stable 60 fps
AppSettings aps = new AppSettings(true);
aps.setVSync(true);
app.setSettings(aps);
app.start();
}
ShootBullet shb = new ShootBullet();
@Override
public void simpleInitApp() {
shb.shootObj(assetManager);
starting();
shb.shootBullets(assetManager);
rootNode.attachChild(shb.shotGroup);
}
@Override
public void simpleUpdate(float tpf)
{
shb.moveBullet(tpf);
shb.rotateObj(tpf);
}
public void starting () {
guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
BitmapText ch = new BitmapText(guiFont, false);
ch.setSize(guiFont.getCharSet().getRenderedSize());
ch.setText("Shooting Cube!"); // crosshairs
ch.setColor(new ColorRGBA(1f,0.8f,0.1f,1f));
ch.setLocalTranslation(settings.getWidth()*0.3f,settings.getHeight()*0.1f,0);
guiNode.attachChild(ch);
viewPort.setBackgroundColor(ColorRGBA.Gray);
flyCam.setMoveSpeed(30);
cam.setLocation(new Vector3f(0f,3f,30f));
}
}[/java]
So, I will appreciate any help.