Jump to content

Sprite collision with moving sprite still happens when moving


Recommended Posts

Sorry, the title might not be the most descriptive. Basically, what I have is I have me, a box, and a moving platform, see here:




Now, the platform moves independently and it moves left and right. The part that confuses me, is that if I jump into the platform from the side (as pictured), I can "stick" to it and move with it. I don't want to be able to do this, but I'm not sure what to look up. Any ideas?

Link to comment
Share on other sites

I've uploaded a live demo here: http://seiyria.com/defiled-dreams/


I've also found out that it happens with the fading blocks. 

I have some physics variables set:

  • body.moves = false for the fading blocks
  • body.allowGravity = false, body.immovable = true for the platforms. 

So far I've tried changing a few variables around and it didn't help a whole lot. I've also tried setting body.mass on players and platforms, and it seems to not do anything. 

Link to comment
Share on other sites

    this.game.physics.collide(this.game.player.ref, this.fadingBlocks, (function(_this) {      return function(ref, block) {        if (ref.body.touching.down) {          return _this.game.player.onBlock = true;        }        else {            ref.body.velocity.y=ref.body.gravity.y;            return _this.game.player.onBlock = false;          }      };    })(this), (function(_this) {      return function(ref, block) {        return block.currentFrame.index === 0;      };    })(this));    this.game.physics.collide(this.game.player.ref, this.platforms, (function(_this) {      return function(player, platform) {        if (player.body.touching.down) {          _this.game.player.onPlatform = true;          return platform.body.velocity.copyTo(player.body.velocity);        }          else {            player.body.velocity.y=player.body.gravity.y;            _this.game.player.onPlatform = false;          }        };    })(this));

Try this out, seiyria. But you need to move Player function on top first (or gravity thing won't be defined). If I'll figure out some better way, I'll let you know right away.

Link to comment
Share on other sites

Bumping again. I have no leads yet, but one thing that was suggested to me was to store the velocity before doing any collision, then restore the velocity when touching right or left, and moving the player sprite. Sample code here for example: http://pastebin.com/Z7DhcrBY


I still am not fond of this solution because it would require me to implement it in each chunk of collision code, but it's a start.

Link to comment
Share on other sites



I think I came up with a workable solution for the time being. What I do is I store the velocity at the beginning of the update function call, and if I should restore that velocity (ie, I bump into a platform or a block in my case), then before I update the player, I restore the velocity. It's not perfect, but it's better than it was. Hope that helps!

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.

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.


  • Recently Browsing   0 members

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