Is it possible to use 'sprite move to another sprite' on Matter.js?

Hello everyone
I’m using Phaser 3 with matter physics
Is it possible to use ‘sprite move to another sprite’ on Matter.js?

From Arcade
I using
this.physics.moveToObject(Sprite1,Sprite2, 300);

but for Matter
it can’t use this.matter.moveToObject(Sprite1,Sprite2, 300);

any idea??? thank
or use
tween???
var tween = this.tweens.add({
targets: Sprite1,
x: Sprite2.x,
y: Sprite2.y ,
duration: 3000,
});

but I think it is not best way, Thank you very much

You could also set its velocity to make it go towards something. I have this old piece of code, I think I took it from Rich, just modified a bit.

const velocityToTarget = (from, to, speed = 1) => {
 const direction = Math.atan((to.x - from.x) / (to.y - from.y));
 const speed2 = to.y >= from.y ? speed : -speed;

 return { velX: speed2 * Math.sin(direction), velY: speed2 * Math.cos(direction) };
};
2 Likes

Oh!! Thanks for your help!!!
It works for me, Have a nice day! :grinning::relaxed:
thank again