Hi, I am trying to shoot spheres in my game but I don’t know why when I am shoot a sphere appears this:
The code i am using to generate the sphere is this:
[java]if (name.equals(“Mouse_Right”) && keyPressed) {
// 1. Reset results list.
CollisionResults results = new CollisionResults();
// 2. Aim the ray from cam loc to cam direction.
Ray ray = new Ray(myMain.getCamera().getLocation(), myMain.getCamera().getDirection());
// 3. Collect intersections between Ray and Shootables in results list.
myMain.getRootNode().collideWith(ray, results);
// 4. Print the results
//System.out.println("----- Collisions? " + results.size() + “-----”);
// 5. Use the results (we mark the hit object)
if (results.size() > 0) {
try{
Sphere s = new Sphere(16, 16, 1);
Geometry geom = new Geometry("Box", s);
Material mat = new Material(myMain.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Blue);
geom.setMaterial(mat);
geom.setLocalTranslation(results.getCollision(0).getContactPoint());
myMain.getRootNode().attachChild(geom);
}catch(NullPointerException e){}
}
}[/java]
Can someone help me, please!!