Jump to content

Unexpected physics results after reset


drhayes
 Share

Recommended Posts

Here's a demo: https://dl.dropboxusercontent.com/u/75126/resurrectweirdness/index.html

 

Using the arrow keys, touch the checkpoint to the left, then fall off the platform to your death. What I want to happen is the sprite is reset at the checkpoint. What actually happens is hard to describe... it looks like the velocity and acceleration of the sprite are all messed up with abnormally large values but, truthfully, I'm at a loss.

 

Here are some relevant code snippets:

 

First, I have an object on the game instance called tulpa. It has properties on it like "player", and "onPlayerKilled". I have a special "onPlayerKilled" signal instead of subscribing to the player's onKill signal because the player might not be instantiated when plugins subscribe to the onPlayerKilled signal. But anyway.

 

There's a plugin called CheckpointPlugin. In its ctor it does this:

  this.currentCheckpoint = null;  game.tulpa.onPlayerKilled.add(function() {    if (this.currentCheckpoint) {      var c = this.currentCheckpoint;      game.tulpa.player.reset(c.position.x, c.position.y - 16);    }  }.bind(this));

In its update method it does this:

      game.physics.arcade.overlap(this.checkpoints, game.tulpa.player,          function(player, checkpoint) {        if (this.currentCheckpoint && this.currentCheckpoint !== checkpoint) {          this.currentCheckpoint.activated = false;        }        this.currentCheckpoint = checkpoint;        this.currentCheckpoint.activated = true;      }.bind(this));

Player's update method has this snippet:

  if (body.velocity.y > constants.LETHAL_DROP_VELOCITY && this.alive) {    // TODO: Play falling death animation then kill.    this.kill();    game.tulpa.onPlayerKilled.dispatch();  }

I *believe* it's the call to reset that causes pain, just not sure why. I played around setting the reset call to hardcoded values and it looks like once I get past an x of about 350 the collisions go haywire and fling my sprite to the right of the map.

 

Any ideas?

Link to comment
Share on other sites

I had reset issues too, I have a feeling they're to do with manually setting the X and Y positions.. it seems to be fine if you do it before you enable physics. But setting them while physics are enabled makes everything screwy.

 

The quick and dirty way I did it was destroying my player, and rebuilding him into the game as I did in the create() function.

 

You could try disabling the physics before manually moving him, but that only works if my initial theory is true. I might be talking out of my butt without knowing it.

Link to comment
Share on other sites

Not to be the guy who just posts "BUMP" and waits expectantly for a response, but...

 

Anyone else have any ideas why this is happening? I think it's collision detection related, but having a hard time deciding how to attack the problem, where to set the breakpoints, what I should be looking for, etc.

 

I'll try temporarily disabling the physics on my player sprite when it respawns but I'm not hopeful about the chances of that succeeding – too many things outside of the player depend on the player having a body to collide with.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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