Tween Cube Movement

I am working on making the movements of my cubes smoother, since right now I only have them changing position with the setPosition(). The program runs fine, but the cube does not move when clicked. I’m not sure where the issue is.
Project Editor: PlayCanvas | HTML5 Game Engine

var Cube = pc.createScript('cube');

Cube.attributes.add('setPosition', { type: 'vec3' });
Cube.attributes.add('viewPosition', { type: 'vec3' });

// initialize code called once per entity
Cube.prototype.initialize = function() {
    this.objName = this.entity.name;

    this.app.on('update:position', this.onUpdatePosition, this);

    this.entity.on('destroy', function() {
        this.app.off('update:position', this.onUpdatePosition, this);
    }, this);
};

// update code called every frame
Cube.prototype.onUpdatePosition = function(name) {
    if (this.objName === name) {
        //this.entity.setPosition(this.viewPosition);
        this.entity.tween(this.setPosition).to(this.viewPosition, 1 , pc.SineOut);
    } else {
        this.entity.setPosition(this.setPosition);
    }
};

Here is the Link to my Project also: PlayCanvas 3D HTML5 Game Engine

Hi @Mayme_T!

Did you already try to check if the function is executed correctly? You can add console.log('Check') to your function and use the console of your browser to see if this line is executed.

https://developer.playcanvas.com/en/user-manual/scripting/debugging/

Also make sure the script is saved. Normally the orange color indicates that the script is unsaved and not working with the latest changes you have made.

image

The function is being executed after using the console.log(‘Check’). Once the object is clicked I receive the ‘Check’ in the console.

I found two issues.

The rigidbodies are static, so they should not move. I suggest to make them kinematic.

The tween is missing .start() at the end of the line.

this.entity.tween(this.setPosition).to(this.viewPosition, 1 , pc.SineOut).start();