seiyria Posted February 19, 2014 Share Posted February 19, 2014 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 More sharing options...
seiyria Posted February 20, 2014 Author Share Posted February 20, 2014 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 blocksbody.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 More sharing options...
Artem Posted February 21, 2014 Share Posted February 21, 2014 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 More sharing options...
seiyria Posted February 22, 2014 Author Share Posted February 22, 2014 This sorta works, but it's a really unnatural push downwards, I think. Also, for this to be globally applicable I'm not sure if it's a good idea to modify each collision individually. I'm still trying to find a more global solution. Link to comment Share on other sites More sharing options...
srikarg Posted February 22, 2014 Share Posted February 22, 2014 Bump. I have the same problem. The player in my game sticks to the sides of any platform and stays there (although he does slowly move down). Link to comment Share on other sites More sharing options...
seiyria Posted March 2, 2014 Author Share Posted March 2, 2014 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 More sharing options...
seiyria Posted March 2, 2014 Author Share Posted March 2, 2014 @srig99 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! srikarg 1 Link to comment Share on other sites More sharing options...
rcsole Posted March 2, 2014 Share Posted March 2, 2014 Just a thought, maybe this could work: add a collision callback and when the two objects are touching, do something like player.body.x -=1 or +=1 Link to comment Share on other sites More sharing options...
Recommended Posts