Retrieve specific location when hit by ball

Hello friends,

I am working on a simple game, which is working well now. I am able to hit a ball, multiple ones on the static image I have put on as a goal. There are two problems I am facing now. I will be posting screenshots for understanding.

  1. When the user hits a specific location of the goal, as mentioned in the image below, I would like to show an alert, like “Hey, you got 10 points”. As it’s just a static image, I don’t know how to proceed with the problem.
  2. I tried the BetterCharacterControl, but cannot find the gravity and other game controls I require for it. And CharacterControl does not want to rotate. I already tried the code from last thread, none helped. tried many manipulations to it as well, the character did not even move by single degree… So if there is anything which is a combination of both, kindly let me know.

Screenshot :

Now, as you can see in the game, I am able to throw balls at the post, I would just like to know where it hits. And display an alert if it hits the specified box. I will be changing the goal-image to something better.

As you can see the image below, how can I display alert following the image below :

Code :

 @Override
    public void simpleInitApp() {

        initCrossHairs();     
        initKeys();       
        initMark();

        Box box = new Box(23.5f, 30.5f, 1.0f);
        Spatial wall = new Geometry("Box", box);

        Material mat_brick = new Material(
                assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
                // Cartoon.jpg below is the goal post
        mat_brick.setTexture("ColorMap",
                assetManager.loadTexture("Textures/cartoon.jpg"));

        wall.setMaterial(mat_brick);

        rootNode.attachChild(wall);
        
            com.jme3.bullet.collision.shapes.CollisionShape sceneShape =
                CollisionShapeFactory.createMeshShape(sceneModel);
        landscape = new RigidBodyControl(sceneShape, 0);
        sceneModel.addControl(landscape);
        
        
          CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1.5f, 6f, 1);
        player = new CharacterControl(capsuleShape, 0.05f);
        player.setJumpSpeed(20);
        player.setFallSpeed(30);
        player.setGravity(30);
        player.setPhysicsLocation(new Vector3f(0, 5, -50));

        rootNode.attachChild(sceneModel);
        bulletAppState.getPhysicsSpace().add(landscape);
        bulletAppState.getPhysicsSpace().add(player);

        shootables = new Node("Shootables");

        rootNode.attachChild(shootables);
        
        
        // Shooting code :
        
        
         public void makeCannonBall() {
    
        Geometry ball_geo = new Geometry("cannon ball", sphere);
        ball_geo.setMaterial(stone_mat);
        rootNode.attachChild(ball_geo);
      
        ball_geo.setLocalTranslation(cam.getLocation());
      
        ball_phy = new RigidBodyControl(1f);

        ball_geo.addControl(ball_phy);

        bulletAppState.getPhysicsSpace().add(ball_phy);
       
        ball_phy.setLinearVelocity(cam.getDirection().mult(75));
    }

Here is the public download URL from dropbox for the entire game(965Kb) in zip file. Kindly have a look. Thank you. :smile:

I see that you’re using Bullet so check here. I think the Physics Collision Listener is what you need for the first problem.