Hi,
I’m working on the weapon system for my game and this is the update method of a controller I have:
public void update(float speed) {
if (vessel.getWeapon().isTriggerDown()) {
// Try to fire a shot, if the weapon isn’t finished reloading it
// will return null.
Shot shot = vessel.getWeapon().fire();
if (shot == null) return;
// Get hit results.
PickResults results = new BoundingPickResults();
//results.clear();
scene.findPick(shot, results);
System.out.println(results.getNumber());
// Handle hit results.
if (results.getNumber() > 0) {
// TODO Handle hit results
System.out.println(shot.getShooter().getName() + " hit " + results.getPickData(0));
}
// Create a line.
Vector3f[] vertex = {
shot.getOrigin(),
shot.getDirection().mult(1000)
};
ColorRGBA[] color = {
new ColorRGBA(1,0,0,1),
new ColorRGBA(1,0,0,1)
};
scene.attachChild(new Line(“Line”, vertex, null, color, null));
}
}
When isTriggerDown() == true I get this:
INFO: Child (Line) attached to this node (rootNode)
java.lang.NullPointerException
at com.jme.scene.Geometry.applyStates(Unknown Source)
at com.jme.scene.Geometry.draw(Unknown Source)
at com.jme.scene.Line.draw(Unknown Source)
at com.jme.scene.Spatial.onDraw(Unknown Source)
at com.jme.scene.Node.draw(Unknown Source)
at com.jme.scene.Spatial.onDraw(Unknown Source)
at com.jme.renderer.lwjgl.LWJGLRenderer.draw(Unknown Source)
Any ideas?
/Per