I’m working on a simple multiplayer game using Colyseus (I know about Geckos, but Colyseus is a better fit for what I’m doing), and basically 20 times a second a new state is sent that includes player position data - x and y. Players can move at 4 units (x/y) every 50ms, aka 80 pixels/second (I’m still trying to tweak the speed).
All that works fine, however I’m having a hard time getting players to move without just plain updating their x/y locations manually (Would cause teleportation on some connections), so I want to use velocity or tweening to move the players since they all extend Phaser.Physics.Arcade.Sprite.
What I’ve tried so far:
const newVector = currentVector.lerp(targetVector, dt);
this.setVelocity(newVector.x, newVector.y);
^ That one causes the player to teleport around randomly on large maps, for some reason. It works perfectly with a small game world though.
this.body.setVelocity(vx, vy); // vx and vy are just +/- speed depending on direction
^ This one just… Doesn’t work right. It’s too slow even with speed fairly high, and it’s laggy.
this.body.velocity.normalize().scale(400);
^ This one, however, is really nice on small maps but impossibly laggy on bigger ones
I’ve searched and searched, I’ve looked at example projects, I’ve experimented - but I’m still not able to get something that works well. Can someone please help me, or at least point me in the right direction?
edit: I’m calling all this in the preUpdate function, after super.preUpdate();