The movement of the object on x

I’m trying to make an object move by itself. But no matter what I try, nothing works.

create {
let sprite = this.physics.add.sprite(470, 450, '"sprite');
} 

update {

sprite.body.setVelocityX(200);
}

or

create {
let sprite = this.physics.add.sprite(470, 450, '"sprite');
} 

update {

sprite.x += 2;
}

You get no errors? Change ‘let sprite’ to ‘this.sprite’ (so no ‘let’), and then use ‘this.sprite’ in update.

this did not work, the sprite began to sink into the ground. I forgot to say that
there is an error: “the sprite is not defined”

But no more error right? I guess the sinking is just gravity (and no collision).

yes, not anymore. but I don’t understand how to change it. can you show me, please?

Change what? To add collision follow this tutorial (specifically Part 3 - World Building).

thank you, but that’s not what I’m talking about. I say can you show the correct version of the code, because I don’t understand what I need to change

create {
    this.sprite = this.physics.add.sprite(470, 450, '"sprite');
}
update {
    this.sprite.body.setVelocityX(200);
}

You shouldn’t set velocity every frame though…
I thought you already did this, and then the sprite sunk?

I don’t know, maybe. even when I moved to create, he still fell into the ground. if this is not necessary in every frame, then need to put the code in “create”?

Maybe have a look at this example.