Hello,
I have a problem with the script, I made 3 planes and I animated it with the script, but when I tried to stop the animation, only 1 plane stopped. does anyone have a solution?
Thank you.
const Random = require(‘Random’);
const Animation = require(‘Animation’);
const Reactive = require(‘Reactive’);
const Time = require(‘Time’);
const Diagnostics = require(‘Diagnostics’);
export class Pipe1{
constructor(defaultY0){
this.defaultY0 = defaultY0;
this.timeDriver ;
this.availabe = true;
this.timeDriverParameters = {
durationMilliseconds: 3000,
loopCount: Infinity,
mirror: false
}
}
spawn(plane0,plane1,plane2){
this.availabe=true;
this.timeDriver = Animation.timeDriver(this.timeDriverParameters);
const linear = Animation.samplers.linear(.3, -.3);
const translationAnimation = Animation.animate(this.timeDriver, linear);
plane0.transform.x = translationAnimation;
plane1.transform.x = translationAnimation;
plane2.transform.x = translationAnimation.add(0.02);
let Randomy = Reactive.toRange(Random.random(),-0.15,-0.3)
plane0.transform.y = Randomy.add(0.4);
plane1.transform.y = Randomy;
plane2.transform.y = Randomy.add(0.2);
this.timeDriver.onAfterIteration().subscribe(()=>{
let RandomY = Random.random()
plane0.transform.y = Reactive.toRange(RandomY ,-0.15,-0.3);
plane1.transform.y = Reactive.toRange(RandomY ,-0.15,-0.3).add(0.4);
plane2.transform.y = Reactive.toRange(RandomY ,-0.15,-0.3).add(0.2);
plane2.hidden = false;
});
this.timeDriver.start();
}
Over(){
this.timeDriver.stop()
this.timeDriver.reset()
}
}