Creating an repeatedly moving object
![repeatedly-moving-object_result](/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Frepeatedly-moving-object_result.63e3ada8.gif&w=3840&q=75)
Place the object
Place the objects where the stepping stone should disappear and change the title.
Code
const movebox = WORLD.getObject("BOX(f7b)");
const patrol = new TWEEN.Tween(movebox.position)
.to({ x: "-10" }, 2000)
.repeat(Infinity)
.yoyo(true)
.start();
π«
If you turned on the Body
in Physics
and it appears stationary, donβt
worry. Simply add a few lines (onUpdate
) to the tween, as demonstrated below.
const movebox = WORLD.getObject("BOX(f7b)");
const patrol = new TWEEN.Tween(movebox.position)
.to({ x: "-10" }, 2000)
.repeat(Infinity)
.onUpdate(()=>{movebox.body.needUpdate = true;})
.yoyo(true)
.start();