Jump to content

Problem with tweening of a body


Hamster going HAM
 Share

Recommended Posts

Hey everyone, im pretty new to Panda, but had a great experience this far.

I have a problem using a tween to "interlace" the position of a player from his current, local position, to the position given by the server (in code "newPosX/Y"). If i just set the position, it works fine, but it creates these ugly jumps when there is a lag, it would look better if the playerbody just "slides" to the new position.

 

I have tried it like this:

game.module(    'game.player'    ).require(    'plugins.p2').body(function () {  game.createClass('Player', {  dead: true,  newPosX: 0,  newPosY: 0,    init: function (x, y, name) {    this.body = new game.Body({    mass: 1,    position: [       x / game.scene.world.ratio,       y / game.scene.world.ratio    ],    angularVelocity: 1    });   this.body.addShape(new game.Circle(this.size));   game.scene.world.addBody(this.body);   this.hudcontainer = new game.Container().addTo(game.scene.stage);},        update: function () {         this.sprite.position.x = this.body.position[0];         this.sprite.position.y = this.body.position[1];},        syncwithserver: function (newPosX, newPosY, rotation) {        //this.body.position[0] = this.newPosX;        //this.body.position[1] = this.newPosY        this.newPosX = newPosX;        this.newPosY = newPosY;        this.tween = new game.Tween(this.body.position);        this.tween.to({ x: this.newPosX, y: this.newPosY }, 50);        this.tween.start();        this.sprite.rotation = rotation;},});});   

I deleted some irrelevant code...

 

The "syncwithserver" function currently gets called every 50 ms. The debugger says that "this.tween.start()" has x and y data on both "valuesEnd" and "valuesStart", so a tween between the two positions should be possible.

Can someone tell me where i went wrong? Or would there be a better method to avoid the jumps when a new position should be set?

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...