The goal is to create and place a building with a button, like in RTS games like Age of Empires, Starcraft, Warcraft etc.
No need to do more stuff, the earlier playgrounds of you guys were already my solution. Implementing them in my code just didn’t work out (I’m coming to that).
Usually I know this. I was still doing it, because I was refering to var name, which I initialized in the function.
I figured out that this was the problem all along.
Although I created a unique name with var name = createName(),
for some reason all names at the same time were used, when I called
function onPointerMove(evt) {
if(!clicked) { return; }
scene.getMeshByName(name).position.x = scene.pick(scene.pointerX, scene.pointerY, null, null).pickedPoint.x;
scene.getMeshByName(name).position.z = scene.pick(scene.pointerX, scene.pointerY, null, null).pickedPoint.z;
}
so, all meshes were positioned to the same spot.
When I use the counter in the name, everything is working fine.
Just to show what I mean, how it works now
I’m still curious:
(Without the counter) Even when I refere the mesh in the onPointerMove function with the variables name with which I created a mesh, like
var mesh = new BABYLON.MeshBuilder.CreateMesh(...)
onPointerMove {
mesh.position.x = scene.pick(X)
mesh.position.z = .position.x = scene.pick(Z)
}
all meshes created with this function will be moved.
Example: https://playground.babylonjs.com/#279FW9#65
Basically the same as before. Just to illustrate what I mean.
When I create a new mesh with var mesh = createMesh(), shouldn’t just this currently created mesh be moved, instead of all meshes? I’m trying to understand what is causing this. The main problem is solved.
What I want to achieve with that information, is a way to use my var name = createName() function without a meshCounter.
Maybe when the onPointerMove function is outside, but called inside my function and is given the mesh to move as parameter? I didn’t got that to work, but I believe this should work somehow.
I have similar functions like this, the only difference is, that created meshes have a fixed position and it all works fine. They have a unique name and they move independently.
I hope I made my question clear. If not, no reply wouldn’t be that bad, because I have the solution of my main problem 