Thank you for your comment how can I measure that he has made exactly 1 rotate. Everything works perfectly, just not sure how I can measure that he has made 1 circle and that he is back in his position
is:
// load model
BABYLON.SceneLoader.ImportMesh(null, “./”, “logo-happy-animatie.glb”, scene, function (newMeshes) {
var robot = newMeshes[0];
robot.rotationQuaternion = undefined;
robot.position = new BABYLON.Vector3(0, 0, -80);
robot.rotation.y = 0.80;
function startAnimation()
var alpha = 0;
scene.registerBeforeRender(function () {
robot.rotation.y = Math.sin(alpha) * 3
alpha += 0.01;
})
};
document.querySelector('.animate-button').addEventListener("click", startAnimation)
so to turn just one full circle you need something like
var alpha = 0;
var circleFinished = false;
scene.registerBeforeRender(function () {
robot.rotation.y = alpha;
if (!circleFinished) {
alpha += 0.01;
if (alpha >= 2 * Math.PI) { // one further rotation to complete circle
alpha = 2 * Math.PI;
circleFinished = true;
}
}
})
However the rotation of your robot is 3 * Math.sin(alpha) the maximum value of which is 3 < PI so the robot never completes half a circle. If you want your robot to turn back and forth in complete circles you need the maximum value to be 2 * Math.PI