[SOLVED] Get where the player is walking on TerrainQuad

I have this code to make my terrain:

Material materialTerrain = new Material(assetManager,
        materialTerrain.setTexture("Alpha", assetManager.loadTexture(
        Texture grass = assetManager.loadTexture(
        materialTerrain.setTexture("Tex2", grass);
        materialTerrain.setFloat("Tex1Scale", 64f);
        Texture dirt = assetManager.loadTexture(
        materialTerrain.setTexture("Tex1", dirt);
        materialTerrain.setFloat("Tex2Scale", 64f);
        Texture grassWhite = assetManager.loadTexture(
        materialTerrain.setTexture("Tex3", grassWhite);
        materialTerrain.setFloat("Tex3Scale", 64f);
        Texture heightMapImage = assetManager.loadTexture(
        AbstractHeightMap heightmap = new ImageBasedHeightMap(heightMapImage.getImage());
        terrain = new TerrainQuad("my terrain", 3, 129, heightmap.getHeightMap());

then I get the position where the player are with:

            Vector3f position = player.getPhysicsLocation().clone();
            CollisionResults results = new CollisionResults();
            Ray ray = new Ray(position, new Vector3f(0f, -1f, 0f));
            terrain.collideWith(ray, results);

The Results is returing my terrain, but I need the exacly texture, because in moment it is the only thing distinguishes.
How I can get this? There is a better solution?

(In my cenary I want to give some damage on player who step in certain texture)

Maybe I should load the texture on BufferedImage and compare the pixel (X,Y) and get the color?
It looks good?

I tryied to get it with this tip, but got nothing, even locate this class on SDK to debug. Started to think I don’t get the concepts well because every new thing I want to do I need to go inside the JME to try to understand.

Ok, Ive solved it doing this:
Changing my terrain location
terrain.setLocalTranslation(128, 0, 128);
getting the image, calculating the difference of pixels:
BufferedImage bi = ImageIO.read(new File(“assets/Textures/Terrain/mapa-novo2.png”));
int x = position.getX() > 0 ? (int) position.getX() * 2 : (int) position.getX()2-1 ;
int y = position.getZ() > 0 ? (int) position.getZ() * 2 : (int) position.getZ()2-1 ;
and then, geting the RGB from this pixel.

I guess its not the best solution, but it works for now =)
Dont need to use the Ray anymore.

Any suggestion will be appreciate

1 Like

That’s ok - game development and 3D graphics in general are complicated. It takes years to get really good at these, and if you’re looking in the engine that means you’re putting in the effort to learn. That effort will pay off well.

Suggestion: don’t read assets using the File class. When the game is packaged up for distribution, the file will not be there. Use the asset manager instead.

Also, I don’t believe it’s possible to use JME effectively without frequently reading the source code. But a good understanding of the concepts will make you even more effective.