Jump to content

Smooth texture movement from point to point


emeraldmaster
 Share

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?

Link to comment
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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...