Y Axis only moveToObject

I want to add computer AI into my phaser pong game, and the moveToObject works well for me to move to the ball, the only issue I have is I only want it to move on the Y axis, is there a way to do this?

Use moveTo instead, then you can keep x constant.
For the Y destination use the ball Y - half the paddle height.

You can also try computer.setVelocityY(ball.body.velocity.y); and set a max velocity.

There’s still a couple of kinks, not sure what exactly is going wrong. Can’t get the x position to stay constant, despite it being a hardcoded variable. Short video enclosed. Sorry to be a pain, scratching my head a few hours now

https://liampugh.co.uk/ShareX/qvc4gAzAMP.mp4.

this.ai = function () {

  if (this.ball.x > this.startPositionBall.y) {

    this.physics.moveTo(

      this.enemyPaddle,

      this.startEnemyPaddle.x,

      this.ball.y,

      350

    );

  }

};

Comparing x with y?

Also, there’s no need to compare, just do it every frame.

Such a silly mistake and cost me hours :frowning: it’s still jittery and slight movement back and forth, not sure why but It’s almost perfect.

I want the delay in the computers movement so there’s the chance the player can win, once I work out how to add scenes and work out how to refactor everything I’ll look into having different difficulties so this would give me another way to work it.

Thanks for your help, really appreciated.