Hello First of all I want to say, that I started working with babylon one week ago and so far enjoyed it a lot.
Here are some good Links I want to share that helped me getting started with the project structure:
- A angular template for babylon: GitHub - JohnnyDevNull/ng-babylon-template: This is a basic template project to start with Angular 16.x and BabylonJS
- A Project with the colyseus backend: GitHub - endel/colyseus-babylonjs-boilerplate: BabylonJS + Colyseus: Multiplayer Boilerpate
The reason why im writing is not that I want my concrete problems solved. If you have a solution for me I would take it for sure, but thatâs not the point.
Im more interested about the best practices when creating a board game in general.
- Should I move the meshes by position change or with impulse vector?
- Which are the right masses for the meshes?
- How to move intersecting meshes and keep them standing upwards?
- What does restitution do?
- Whats the best way to rotate Meshes? Rotation or rotationQuaternion?
- Is Colyseus a good way to sync the meshes (position and rotation)?
What I want do do
I played around with some features of Babylon. At some point I added the skybox and physics which lead to some questions in my mind.
I want to develop a board game like monopoly. Here is a screenshot of what I did so far:
What I tried so far
My first goal is that the board is dragable to both sides on the x-Axis in a given range (pictures above). I solved this by adding a PointerDragBehavior to the Board which checks if the new position would be in range before moving.For the figures I did the same but without the range check so they can be moved from the table.
My second goal is that the figures can fall from the table. Therefore I added PhysicsImpostor to the table:
table.physicsImpostor = new BABYLON.PhysicsImpostor(table,
BABYLON.PhysicsImpostor.BoxImpostor, { mass: 0, friction: 1, restitution: 0 }, this.scene);
And for the figures:
figure.physicsImpostor = new BABYLON.PhysicsImpostor(figure, BABYLON.PhysicsImpostor.MeshImpostor, { mass: 1, friction: 0.1, restitution: 0 }, this.scene);
This makes the figures stand on the table.
So far so good.
My third goal is that the figures can stand on the board. Therefore I need to apply a PhysicsImpostor to the board too correct? Same way do did before.
this.boardLeft.physicsImpostor = new BABYLON.PhysicsImpostor(this.boardLeft,*
BABYLON.PhysicsImpostor.BoxImpostor, { mass: 0.01, friction: 0.01, restitution: 0 }, this.scene);
this.boardRight.physicsImpostor = new BABYLON.PhysicsImpostor(this.boardRight,*
BABYLON.PhysicsImpostor.BoxImpostor, { mass: 0.01, friction: 0.01, restitution: 0 }, this.scene);
If I do this, the the figures are be behaving in a strange way like rotating around after movement.
My fourth goal is that if I move the board, the figures standing on it, should also be moved.
I solved that by moving all intersecting meshes in the PointerDragBehavior mentioned above.
// Move all intersecting figures
this.scene.meshes.forEach(mesh => {
if (mesh.parent == null && (mesh.name.startsWith(âsk-figureâ))) {
// Mesh and childMeshes (true)
if (mesh.intersectsMesh(this.brettLeft, true, true)) {
mesh.position.x += event.delta.x;
}
}
});
My observations concluded
- No Impostor set on the board + the positions are by changed by changing the position-Attribute (mesh.position.x, mesh.position.y) â The Figures do not stand on the board because they donât realize it as a collider
- BoxImpostor on the board with mass: 0 â Board cant be moved with a simple position change; somehow it is working if figures is standing on it
- BoxImpostor on the board with mass: 1 â Movement is possible but the boards are pushing against each other and the firgures are sometime behaving strange (rotationâŚ); The board can move behind the defined range because the position is calculated by the physics engine
- BoxImpostor on the board and position change by an impulse-vector â The board can move behind the defined range
- I had no success with trying to disable the physics while dragging or make the collider sleep for some time.
What I didnât try yet
- Make separate collider boxes for the board with visible=false and apply the Impostor only on them
Skybox
Another problem that I have is the skybox. What I want to achieve is something like that: https://www.shangshouculture.com/
Aside from the mountains in the background. I found it in the coummunity project section.
I tried around with the skybox and its attributes but cant change the color of the sky.
What has to be done reach such an effect?
I hope I described my problems in a understandable way =)
If i should provide more code just let me know. Is there a way to create new playgrounds?
Any kind of answer is welcome. Have a nice day!