How to get updated pos?

I want to get updated pos because I want next push into array of positions
but I’m getting the same initial position in this.arrPos I mean it pushing the same position

addPos(){
        if(this.app.keyboard.wasPressed(pc.KEY_P)){
            this.arrPos.push(this.entity.position);
            console.log('pos added');
        }
    }
    
    // update code called every frame
 update(dt) {
        this.addPos();
 }

ok I have it

addPos(pos){
        if(this.app.keyboard.wasPressed(pc.KEY_P)){
            this.arrPos.push(pos);
            console.log('pos added', pos);
        }
    }
    
    

    // update code called every frame
update(dt) {
        this.addPos(this.entity.position);
}

pc.Entity#position is not API. Did you mean to do:

var pos = this.entity.getPosition();

Note that if you want to store off that position and reference/access it later, you should clone it. Otherwise, its value will change every time the entity moves. So:

var pos = this.entity.getPosition().clone();
2 Likes