Sphere displaced

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!!

Just an aside. To a programmer, this: “catch(NullPointerException e){}”… is about the equivalent of hearing a babies laughter in the middle of the night… when you live alone.

1 Like
@pspeed said: Just an aside. To a programmer, this: "catch(NullPointerException e){}"... is about the equivalent of hearing a babies laughter in the middle of the night... when you live alone.

Wait… O.o Should I be going to see someone about this??

@t0neg0d said: Wait... O.o Should I be going to see someone about this??

Heheh… it’s from a well worn joke.

“There is no greater sound than the laughter of a small child… unless it is 3 AM and you live alone.”

1 Like