[SOLVED] How to look at Y axis only?

Nevermind, i forget to remove the old function.

Is there a way to fire the function from the player script?
(The function itself is on the enemy script).

Yes use events, check how I did it in the sample above.

The function is fired from the movement.js script.

Ah i thought it has to be on the same object but it don’t has to.

It works fine now. Thanks a lot!

1 Like

I use a boolean to use a tween in the update. So maybe i can help others to with this example:

this.isStarted = false;
Tween.prototype.update = function(dt) {
    if (this.isStarted === false) {
        this.isStarted = true;
        entity.tween(entity.getLocalPosition())
        .to({x: 10, y: 0, z: 0}, 1, pc.Linear)
        .on('complete', function () {
            console.log('tween completed');
            this.isStarted = false;
        });
    }
};

That’s great! Thanks for sharing, indeed if you make sure that the tween doesn’t start/stop per frame then there is no reason to not have it in your update loop.

By the way this line:

var this.isStarted = false;

Should be like this, a property assignment doesn’t require creating a new var:

this.isStarted = false;
1 Like