Jump to content

Object stuck to moving platform


CoderHog
 Share

Recommended Posts

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:

center.png.5a2a895c7b4d5f3cd4100cea966d6a71.png

After the play jumps over a platform and sticks to it:

moved.png.0000383926a9644a7c51af5ec70dd900.png

 

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

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

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.

Guest
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.

Loading...
 Share

  • Recently Browsing   0 members

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