I’m having problem putting my chess pieces into their proper place on the chessboard. I don’t know if is the same logic as a 2d chess game. I’m new to jmonkeyengine and 3d gaming. I just need some guidance with this part of my project.
Could you give a bit more information please? What is the exact problem you are having?
Well the logic is certainly the same as in a 2D chess game. The only ‘3D’ thing you have to do is getting the position of a chess field. E.g. if you want to place a figure on field E5 you would have to get the position of the field and then set the localTranslation of the figure to the position of the field.
There are multiple ways of getting the position. You could use Quads with a fixed size as chess fields and simply put them all over your board. Then you yould get the position via getLocalTranslation(). Or you know the width and height off the chess fields and calculate the position with it.
I hope I understood your probllem correctly.
Chessboard = (Node) assetManager.loadModel("Models/chessboard.j3o"); //Chessboard.setLocalScale(2f); Spatial bishop = assetManager.loadModel("Models/Bishop.j3o"); Chessboard.attachChild(bishop); Vector3f bishopLoc = new Vector3f(-5, 0, -5); bishopLoc.setY(Chessboard.getLocalTranslation().getY()); bishop.setLocalTranslation(bishopLoc);
this is how i’m setting up my pieces on the chessboard, but i don’t know if this is the correct way to implement a chessboard setup in JME3.
You understood my problem. i did something like this
Vector3f bishopLoc = new Vector3f(-5, 0, -5); bishopLoc.setY(Chessboard.getLocalTranslation().getY()); bishop.setLocalTranslation(bishopLoc);
but wondering if i’m on the correct path.
There will be no single correct way :). However, in this case and someone can correct me if i’m wrong; wouldn’t it be better to use world translation rather than local translation?
Have you tried using the scene graph to initially set this up rather than programatically? I feel this would be easier for starting off :).
i will give the scene graph a tried. Thank you
No worries. Also, in respect to your code; you need to attach the node/model to the scene.
@normen did some fantastic beginners videos on JME. If you watch both the use case 1 & 2 it should set you well on your way to understanding how everything fits together.
It really depends on the objects you are putting in. I suggest that the center or pivot of the chessboard is at the center in x and z axis but on the chessboard’s surface. For the pieces, ensure that the pivot is at the very bottom of the piece, so that the local height can be set to zero (0) and that way they will be at the surface of the board, making things easier to code.
If you can’t edit the models use the scene composer so that the 3D models are children of empty objects with a center in the places I mentioned
I made a chess game in Unity and used these tricks to make the code and math easier and just focus on the AI more.