emeraldmaster

Smooth texture movement from point to point

Recommended Posts

Hi guys, I'm new to game dev, and I need your help

I'm writing basic multiplayer deathmatch game (tanks), server side is almost finished and now I need to adjust the client.

Server sends world updates every 20ms, including updated positions of tanks (x, y and angle). JS client is based on Phaser, but it doesn't use any predefined physics, all calculations are done on server. The problem :

When client receives new position of tank, it has to update position of sprite. Currently this is done in 'update' function:

tank.x = updatedPosition.x;
tank.y = updatedPosition.x;
tank.angle = updatedPosition.angle;

But from user's perspective this movement looks buggy, because his tank 'jumps' from point to point without animation. Is there a way to make this continuous transition more smooth?

Share this post


Link to post
Share on other sites

This is initially due to server-side programming.. If when updating their position, you also updated the current movement, you could have predicted movement which would make the game look far less 'choppy'. In it's place, you could tween the position, though I don't know how useful that'd be but it's worth a shot. 

i.e: this.game.add.tween(tank).to({x: data.x, y: data.y}, 250, Phaser.Easing.Quadratic.In, true, 0);

When the server updates the client on new tank position, you could remove the current tween, with tank.tweens.removeAll(); or something similar, not sure on correct syntax for that. Then create the new tween as above. We leave the easing only in, as if it were easing out, every time it would get a new position data, the tank would increase speed to there, however for continuous movement, you should probably leave it as only easing in. Then if there is no move movement from the server, the tank will slow down to a stop. You could do something quick to check if the tank is moving.. if it is, tween in only, else if it's stopped.. then tween InOut, which would mean the tank would increase speed then travel to it's new cords continuously without looking as choppy. As long as you don't have hundreds of tanks tweening all at once, performance should be pretty good. if it does get choppy, you could change quadratic to just Linear, which would speed things up slightly, but it will look less appealing to the eye.

Hope this is some help

Nick

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.