Listening to or monitoring jitter object's position in js api inside async await func
Hello again, I know that I have been clogging the forum with my questions lately, this one is the last one i swear!
It's unclear for me how to monitor the position of gridshape being transfered by anim.node from one point to another. In the async Promise i have to resolve the function and free memory when animation is done, in other words stop the animation when the end coordinate is reached. Can't find in docs and examples.
function animateImpulse(startCoord, endCoord, speed) {
return new Promise((resolve) => {
post("Calling animateImpulse with:", startCoord, "to", endCoord, "speed:", speed, "\n");
const gridshape = new JitterObject("jit.gl.gridshape", contextName);
gridshape.shape = "cone";
gridshape.color = [Math.random(), Math.random(), Math.random()];
post("Created gridshape");
const animNode = new JitterObject("jit.anim.node");
gridshape.anim = animNode.name;
animNode.movemode = "local";
animNode.scale = impulseScale;
animNode.position = startCoord;
animNode.lookat = endCoord;
animNode.direction = endCoord;
post("Created jit.anim.node");
const animDrive = new JitterObject("jit.anim.drive");
animDrive.targetname = animNode.name;
post("Created jit.anim.drive\n");
// Validate objects before connecting
if (!gridshape || !animDrive || !animNode) {
post("Failed to create gridshape or animPath.");
return resolve();
}
animDrive.move(0, 0, speed);
post("\nMoving node")
/* if (animNode.position[0] === endCoord[0] &&
animNode.position[1] === endCoord[1] &&
animNode.position[2] === endCoord[2]) {
post("\nreached endCoord");
gridshape.freepeer();
animPath.freepeer();
animNode.freepeer();
post("Cleaning and resolving")
resolve();
} */
/* var listener = new JitterListener(animNode.getregisteredname(), callBackResolve);
function callBackResolve(event) {
post(event.eventname);
if(event.subjectname.position = endCoord) {
post("Animation ends")
gridshape.freepeer();
animDrive.freepeer();
animNode.freepeer();
post("Cleaning and resolving")
resolve();
}
} */
});
}
I omitted some other code, only the problematic function and it's call remained. I commented out my unsuccessful attempts. There was another one where I tried to use Task, but it failed as well. I swear i read docs, but can't figure this out.