SnippetTweenBEGINNERRepeatedly Moving Object

Creating an repeatedly moving object


repeatedly-moving-object_result

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();