CoderHog Posted August 18, 2017 Share Posted August 18, 2017 Hi, I'm making a simple platform game in which the player is always at the center of the world and the objects move towards him from right to left. When the player is over a moving platform, it sticks to it and they move together. It removes the player from its original position. I have tried setting the player.body.x to game.world.centerX on update, but it looks clumsy. You can see when the player position is being reseted. update: function () { player.body.x = game.world.centerX; } The documentation shows two body properties that I could use: drag and friction. But I can't get to make any of them work out. This is the position I want the player (white ball) to stay on: After the play jumps over a platform and sticks to it: Does drag/friction work on arcade physics? If so, how could I use it? Should I set one of these properties on the platforms or on the player? Any help is appreciated! Thanks in advance! Link to comment Share on other sites More sharing options...
Matthew Cooley Posted August 18, 2017 Share Posted August 18, 2017 You could make it so the character is the one that is moving and the camera is locked to it. Then set all the environmental objects to be immovable, while applying a steady X velocity to the character on update(), which should prevent any sticking. Link to comment Share on other sites More sharing options...
CoderHog Posted August 18, 2017 Author Share Posted August 18, 2017 3 hours ago, Matthew Cooley said: You could make it so the character is the one that is moving and the camera is locked to it. Then set all the environmental objects to be immovable, while applying a steady X velocity to the character on update(), which should prevent any sticking. It was like that before. The game world was pretty wide and the player was the only moving object. But the game ran at 30 fps or less on mobile. Making a smaller world improved the performance a lot, but made that problem appear. :/ Link to comment Share on other sites More sharing options...
samme Posted August 18, 2017 Share Posted August 18, 2017 I think you want platform.body.drag.x = 0; Link to comment Share on other sites More sharing options...
CoderHog Posted August 19, 2017 Author Share Posted August 19, 2017 1 hour ago, samme said: I think you want platform.body.drag.x = 0; Thanks samme! I forgot about .body. The drag property was already 0, but the friction was set to 1. platform.body.friction.x = 0; It is working real smooth now Link to comment Share on other sites More sharing options...
samme Posted August 19, 2017 Share Posted August 19, 2017 Argh I meant friction, yes. Link to comment Share on other sites More sharing options...
samme Posted August 19, 2017 Share Posted August 19, 2017 Default friction is (1, 0), that's causing the movement you see. CoderHog 1 Link to comment Share on other sites More sharing options...
CoderHog Posted August 19, 2017 Author Share Posted August 19, 2017 I got it know. Thanks a lot! Link to comment Share on other sites More sharing options...
Recommended Posts