Select a point on the floor

Hi Guys ,

i tried to select a point in my level using the monkey platform

but i always end selecting a point in the space without hitting

the floor or the level, is there a fast way to achieve this?

My level has 2 floors and i want to use these points to create a path.



Thanks

You probably hit the sky sphere if you added a sky. When you right-click the scene the cursor is placed at the first geometry collision or if theres no geometry the first bounding box.

Thank you Normen.

You can also divide up your scene graph into something like:



Collidables

OtherNodes



When you do your picking… do it against the Collidables nodes only. This way, you’ll never select your skybox, or any other items that are outside of the list of geoms you care about.

The SDK cursor will collide with anything still :wink:

Is there something wrong in this code?

It is very messy but apart from that i take the points in the scene composer and when i try to run

the game the model moves in two points translated respect to the point i take





import java.io.File;

import java.io.IOException;

import java.util.Iterator;

import java.util.LinkedList;

import java.util.List;







import com.jme3.animation.AnimChannel;

import com.jme3.animation.AnimControl;

import com.jme3.app.SimpleApplication;

import com.jme3.bullet.BulletAppState;

import com.jme3.bullet.PhysicsSpace;

import com.jme3.bullet.collision.shapes.CapsuleCollisionShape;

import com.jme3.bullet.collision.shapes.CollisionShape;

import com.jme3.bullet.control.CharacterControl;

import com.jme3.bullet.control.RigidBodyControl;

import com.jme3.bullet.util.CollisionShapeFactory;

import com.jme3.cinematic.MotionPath;

import com.jme3.cinematic.events.MotionTrack;

import com.jme3.export.binary.BinaryExporter;

import com.jme3.input.KeyInput;

import com.jme3.input.controls.ActionListener;

import com.jme3.input.controls.KeyTrigger;

import com.jme3.light.DirectionalLight;

import com.jme3.material.Material;

import com.jme3.math.ColorRGBA;

import com.jme3.math.FastMath;

import com.jme3.math.Quaternion;

import com.jme3.math.Vector3f;

import com.jme3.scene.Geometry;

import com.jme3.scene.Mesh;

import com.jme3.scene.Node;

import com.jme3.scene.Spatial;

import com.jme3.scene.control.Control;

import com.jme3.util.SkyFactory;

import com.thehammer.controls.NavMeshNavigationControl;

import com.thehammer.navigation.NavMesh;

import com.thehammer.navigation.Path.Waypoint;

import com.thehammer.navigation.util.GeometryBatchFactory;

import com.thehammer.navigation.util.NavMeshGenerator;

/**

  • Example 9 - How to make walls and floors solid.
  • This version uses Physics and a custom Action Listener.
  • @author normen, with edits by Zathras

    /

    public class TestScene extends SimpleApplication

    implements ActionListener {

    private Node sceneModel;

    private BulletAppState bulletAppState;

    private RigidBodyControl landscape;

    private CharacterControl player;

    private AnimChannel channel;

    private AnimControl control;

    private MotionPath path;



    CharacterControl player2Control ;

    public MotionPath getPath() {



    return path;

    }





    public void setPath(MotionPath path) {

    this.path = path;

    }



    private MotionTrack motionControl;

    private NavMesh navMesh = new NavMesh();

    NavMeshNavigationControl navControl;



    BinaryExporter exporter = new BinaryExporter();

    Node player2;





    private Vector3f walkDirection = new Vector3f();

    private boolean left = false, right = false, up = false, down = false;

    public static void main(String[] args) {

    TestScene app = new TestScene();

    app.start();

    }





    private PhysicsSpace getPhysicsSpace() {

    return bulletAppState.getPhysicsSpace();

    }

    public void simpleInitApp() {

    /
    * Set up Physics /

    bulletAppState = new BulletAppState();

    stateManager.attach(bulletAppState);

    // We re-use the flyby camera control for rotation, while positioning is handled by physics

    viewPort.setBackgroundColor(new ColorRGBA(0.7f,0.8f,1f,1f));

    flyCam.setMoveSpeed(100);

    setUpKeys();

    setUpLight();

    path = new MotionPath();



    path.addWayPoint(new Vector3f(-120.775734f, -141.69344f, 306.80966f));

    path.addWayPoint(new Vector3f(-474.26135f, -58.358093f, 351.14462f));



    path.enableDebugShape(assetManager, rootNode);













    rootNode.attachChild(SkyFactory.createSky(

    assetManager, “Textures/Sky/Bright/BrightSky.dds”, false));

    // We load the scene from the zip file and adjust its size.

    sceneModel =(Node) assetManager.loadModel(“Models/monastero/monastero.j3o”);

    sceneModel.setLocalScale(0.6f);



    createNavMap();

    player2 = (Node) assetManager.loadModel(“Models/Frate/Frate.j3o”);





    player2.scale(0.1f, 0.1f, 0.1f);

    motionControl = new MotionTrack(player2,path);

    motionControl.setDirectionType(MotionTrack.Direction.PathAndRotation);

    motionControl.setRotation(new Quaternion().fromAngleNormalAxis(-FastMath.HALF_PI, Vector3f.UNIT_Y));

    motionControl.setInitialDuration(10f);

    motionControl.setSpeed(1f);





    navControl = new NavMeshNavigationControl(navMesh);

    CapsuleCollisionShape capsule = new CapsuleCollisionShape(3f, 4f);

    player2Control = new CharacterControl(capsule, 10f);



    //player2.addControl(player2Control);

    //player2.addControl(navControl);

    player2.addControl(motionControl);

    player2Control.setJumpSpeed(20);

    player2Control.setFallSpeed(30);

    player2Control.setGravity(30);

    player2Control.setPhysicsLocation(new Vector3f(-120.775734f, -141.69344f, 306.80966f));



    getPhysicsSpace().add(player2Control);



    // navControl.setPosition( navControl.warp(new Vector3f(-64.601074f, -153.45349f, 307.15338f)));

    //navControl.computePath(navControl.warp(new Vector3f(-474.26135f, -58.358093f, 351.14462f)));













    sceneModel.attachChild(player2);



    // We set up collision detection for the scene by creating a

    // compound collision shape and a static physics node with mass zero.

    CollisionShape sceneShape = CollisionShapeFactory.createMeshShape((Node) sceneModel);

    landscape = new RigidBodyControl(sceneShape, 0);

    sceneModel.addControl(landscape);

    // We set up collision detection for the player by creating

    // a capsule collision shape and a physics character node.

    // The physics character node offers extra settings for

    // size, stepheight, jumping, falling, and gravity.

    // We also put the player in its starting position.

    CapsuleCollisionShape capsuleShape = new CapsuleCollisionShape(1.5f, 6f, 1);

    player = new CharacterControl (capsuleShape, 10f);

    player.setJumpSpeed(20);

    player.setFallSpeed(30);

    player.setGravity(30);

    player.setPhysicsLocation(new Vector3f(20, 65, 150));

    // We attach the scene and the player to the rootnode and the physics space,

    // to make them appear in the game world.

    rootNode.attachChild(sceneModel);

    bulletAppState.getPhysicsSpace().add(landscape);

    bulletAppState.getPhysicsSpace().add(player);

    }

    private void setUpLight() {

    // We add light so we see the scene



    DirectionalLight dl = new DirectionalLight();

    dl.setColor(ColorRGBA.White);

    dl.setDirection(new Vector3f(2.8f, -2.8f, -2.8f).normalizeLocal());

    rootNode.addLight(dl);



    }







    /
    * We over-write some navigational key mappings here, so we can
  • add physics-controlled walking and jumping: /

    private void setUpKeys() {

    inputManager.addMapping(“Lefts”, new KeyTrigger(KeyInput.KEY_A));

    inputManager.addMapping(“Rights”, new KeyTrigger(KeyInput.KEY_D));

    inputManager.addMapping(“Ups”, new KeyTrigger(KeyInput.KEY_W));

    inputManager.addMapping(“Downs”, new KeyTrigger(KeyInput.KEY_S));

    inputManager.addMapping(“Jumps”, new KeyTrigger(KeyInput.KEY_SPACE));

    inputManager.addListener(this, “Lefts”);

    inputManager.addListener(this, “Rights”);

    inputManager.addListener(this, “Ups”);

    inputManager.addListener(this, “Downs”);

    inputManager.addListener(this, “Jumps”);

    }

    /
    * These are our custom actions triggered by key presses.
  • We do not walk yet, we just keep track of the direction the user pressed. */

    public void onAction(String binding, boolean value, float tpf) {

    if (binding.equals(“Lefts”)) {

    left = value;

    } else if (binding.equals(“Rights”)) {

    right = value;

    } else if (binding.equals(“Ups”)) {

    up = value;

    } else if (binding.equals(“Downs”)) {

    down = value;

    } else if (binding.equals(“Jumps”)) {

    player.jump();

    }



    }

    /**
  • This is the main event loop–walking happens here.
  • We check in which direction the player is walking by interpreting
  • the camera direction forward (camDir) and to the side (camLeft).
  • The setWalkDirection() command is what lets a physics-controlled player walk.
  • We also make sure here that the camera moves with player.

    */

    @Override

    public void simpleUpdate(float tpf) {

    Vector3f camDir = cam.getDirection().clone().multLocal(0.6f);

    Vector3f camLeft = cam.getLeft().clone().multLocal(0.4f);

    walkDirection.set(0, 0, 0);

    if (left) { walkDirection.addLocal(camLeft); }

    if (right) { walkDirection.addLocal(camLeft.negate()); }

    if (up) { walkDirection.addLocal(camDir); }

    if (down) { walkDirection.addLocal(camDir.negate()); }

    player.setWalkDirection(walkDirection);

    cam.setLocation(player.getPhysicsLocation());

    motionControl.play();











    }





    public void createNavMap(){















    NavMeshGenerator generator = new NavMeshGenerator();

    GeometryBatchFactory.optimize(sceneModel);

    Mesh mesh = findGeometries(sceneModel).getMesh();



    Mesh optiMesh = generator.optimize(mesh);



    navMesh.loadFromMesh(optiMesh);

    //TODO: navmesh only for debug

    Geometry navGeom = new Geometry(“NavMesh”);

    navGeom.setMesh(optiMesh);

    Material green = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);

    green.setColor(“Color”, ColorRGBA.Green);

    green.getAdditionalRenderState().setWireframe(true);

    navGeom.setMaterial(green);











    rootNode.attachChild(navGeom);





    }



    private Geometry findGeometries(Node node) {

    for (Iterator it = node.getChildren().iterator(); it.hasNext():wink: {

    Spatial spatial = it.next();

    if (spatial instanceof Geometry) {

    return(Geometry)spatial;

    }

    }

    return null;

    }

You probably need to use getWorldTranslation() somewhere instead of getLocalTranslation(): https://wiki.jmonkeyengine.org/legacy/doku.php/jme3:scenegraph_for_dummies