Recent Profile Visitors

@JohnK I've already read that page. Be more specifically, in this demo, i want to move the cylinder's location to (0,0,1), but not using the position.z += 1, use the local frame of reference and a local orientation vector to finish the translation.And calculate the correct segment's vertex position while need it.

Here's the demo.
https://www.babylonjs-playground.com/#LS4I1S
Firstly, I want to move the cylinder forward(in local axes), so i use mesh.translate(BABYLON.Vector3.Forward(), 1). The cylinder move 1 unit in the y axis instead of z axis(that's what i want), I can understand why the cylinder move in the y axis(because of the rotation), but I want to know how to move the cylinder on the x-z plane forward after rotation by using the local frame of reference.
Secondly, how to compute the segments' two end points dynamically, is my code right?
this.mesh.computeWorldMatrix();
let matrix = this.mesh.getWorldMatrix(true);
this.vertex1 = BABYLON.Vector3.TransformCoordinates(this.vertex1, matrix);
this.vertex2 = BABYLON.Vector3.TransformCoordinates(this.vertex2, matrix);
(My english is poor, please forgive me)

@jerome @Magilla I know what you guys mean. But my point is, my expecting code behavior is to generate a series of spheres instead of just 3. And if you add snake.pop().dispose() before each render, you will see there's only one sphere, not three.

@Deltakosh Thanks for your answer, but as for my first question, I expected that will produce a series of spheres, but there're only three spheres existed all the time, I want to know what's wrong with my implementation.

I want to create new mesh before each render, here's my code:
let snake = [
sphere1,
sphere2,
sphere3
];
(function(){
let counter = 4;
scene.registerBeforeRender(function(){
let newOne = BABYLON.MeshBuilder.CreateSphere(
"sphere" + counter,
{
},
scene
);
let head = snake[0];
newOne.position = head.position;
newOne.position.x += 0.02;
snake.unshift(newOne);
++counter;
});
})();
My expecting behavior is to create a series of spheres, each position.x is slightly higher than the previous one. However, there are only three meshes in the scene after rendering, like this:
I want to know what is wrong with my code, and how to implement it properly?
By the way, what is the difference between scene.removeMesh(mesh) and mesh.dispose()?
Here's the relative link in stackoverflow:
https://stackoverflow.com/questions/50235364/create-mesh-before-render-in-babylon-js