Mercutio Posted July 19, 2018 Share Posted July 19, 2018 Hi, I am trying to build a platformer and when my player is standing on a vertically moving platform it hops at the peak right when it changes direction. In the real world it makes sense but unwanted in game... Does anyone have any suggestions how to fix the issue? Some context: I am using arcade physics. I am moving my platform using velocity as I understand it I need to do it that way so the player sticks for horizontal movement. Thanks Do you guys need to see my code for this? if so which part? Link to comment Share on other sites More sharing options...
samme Posted July 19, 2018 Share Posted July 19, 2018 You can try setting body.friction.y = 1 on the platform. Link to comment Share on other sites More sharing options...
Mercutio Posted July 21, 2018 Author Share Posted July 21, 2018 Setting the body.friction.y to 1 for both/either the player and/or the platform didn't do anything :( unfortunately. Link to comment Share on other sites More sharing options...
Mercutio Posted July 24, 2018 Author Share Posted July 24, 2018 No one knows the answer? :( Link to comment Share on other sites More sharing options...
samme Posted July 24, 2018 Share Posted July 24, 2018 It's not straightforward using the physics mechanics. You could set the sprite body's bounce.y = -1 or gravity.y = a large positive number when it contacts the platform, then change it back to release the sprite. The other way is to set body.moves = false while the sprite is on the platform and position it manually. Link to comment Share on other sites More sharing options...
Mercutio Posted July 26, 2018 Author Share Posted July 26, 2018 For those who have a similar problem, here's what I ended up doing seems to work well enough. Don't know how fail safe or efficient it is though. //in the scene this.physics.add.collider(player, platforms, ride); //collision callback with platforms function ride(object1, object2){ //check for if you actually step on the platform not just collide if(object1.body.touching.down) { object1.ride(object2); } } //in player object ride(rideObject){ this.riding = true; this.rideObject = rideObject; } //in update after movement if(this.riding){ this.y = this.rideObject.y - (this.height/2 + this.rideObject.height/2); if(this.key_W.isDown || this.x < this.rideObject.x - this.rideObject.width/2 || this.x > this.rideObject.x + this.rideObject.width/2 ){ //jump // fall off this.riding = false; } } Link to comment Share on other sites More sharing options...
Recommended Posts