Trying to get Control of a ball

Hello, my task is to get control of a ball by using the left click button. Basically when you click the left mouse button, the ball will come directly into the screen and when you release it, it will continue moving.
[java]
private Geometry ball1, ball2;

public void simpleInitApp() {

sphere1 = new Sphere(32, 32, 2f);
ball1 = new Geometry(“Blue Ball”, sphere1);
sphereCollisionShape = new SphereCollisionShape(0.4f);
ball1.setLocalTranslation(10, 5, 0);
Material mat1 = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
mat1.setColor(“Color”, ColorRGBA.Blue);
ball1.setMaterial(mat1);
ball1.addControl(new RigidBodyControl(50f));
this.rootNode.attachChild(ball1);
this.getPhysicsSpace().add(ball1);

}

inputManager.addMapping(“Click”, new MouseButtonTrigger(MouseInput.BUTTON_LEFT));

inputManager.addListener(this, “Click”);

public void simpleUpdate(float tpf) {
if (click) {
ball1.setLocalTranslation(5, 5, 5);

    }

}
[/java]

ball1.setLocalScale works fine, if i click the ball gets bigger but i want to control the balls translations.

Sorry i also have cam directions:
[java]
private Vector3f walkDirection = new Vector3f();
private Vector3f camDir = new Vector3f();
private Vector3f camLeft = new Vector3f();
[/java]

Can you explain more detailed what you mean by “the ball will come directly into the screen”?

You’re saying you want to move the ball when you click on it, and that it doesn’t move but it gets bigger. Yet you have no code that scales the ball1 object. Maybe it just looks like it’s getting bigger because it’s moving towards the camera?

@fowlie said: Can you explain more detailed what you mean by "the ball will come directly into the screen"?

You’re saying you want to move the ball when you click on it, and that it doesn’t move but it gets bigger. Yet you have no code that scales the ball1 object. Maybe it just looks like it’s getting bigger because it’s moving towards the camera?

I will put it in simplest terms, i want to control the xyz cordinates of a ball/Geometry with a left mouse button click. In my if statement (click), i can control the balls scale with ball1.setLocalScale (so if i click the left mouse button it gets bigger) however, i want to control the translation.

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:physics

@normen said: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:advanced:physics

Ok so i got the ball to follow me when i left click with
[java]
if (click) {

        ball1.getControl(RigidBodyControl.class).setPhysicsLocation(player.getPhysicsLocation());
        bulletAppState.getPhysicsSpace().add(ball1);

}
[/java]

However, i want the ball into the front of the screen. Does anyone know how to add vectors in Java? I want to add player.getPhysicsLocation() + some Vector.

https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:math_for_dummies
(I grab these from the sidebar to the right of your screen btw)

1 Like
@normen said: https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:math_for_dummies (I grab these from the sidebar to the right of your screen btw)

Sorry for being a nuiscance and thanks normen!