markjsb

Problem with Arcade Physics on mobile

Recommended Posts

This is purely a mobile issue, desktop is perfect.

 

I have a platform game and unfortunately there are random instances when it just falls through the tilemap.

 

It usually happens on the first play and then randomly on the third or fourth level.

 

I've tried on Nexus 4 and Nexus 7 and it is the same. I've tried CocoonJS and same there.

 

As I say works fine on desktop. Any ideas how I can get this working? Is a different physics worth trying (currently arcade physics)? 

 

Anyone else had this problem.

 

Thanks for your help  :)

 

Share this post


Link to post
Share on other sites

Update, it works fine in Nexus 7 through CocoonJS, very occasionally in the browser it screws up.

 

So I think it's a problem with mobile, I chose this library because it had been developed specifically for mobile browsers. So again I ask anyone had issues running on mobile where physics are too strong and the player occasionally falls through the floor (tilemap)?

Share this post


Link to post
Share on other sites

I also had this problem on my Android device (since performance is so bad). What I finally found out was that if I decreased the gravity enough this didn't happen any more, so it could be a good idea to try lowering the gravity and see if that helps.

Share this post


Link to post
Share on other sites

Thanks Karma Octopus. I increased the gravity because the physics take forever to bring the player back to ground, it just doesn't feel right. Looks like I might have to give P2 a try, better get reading...

Share this post


Link to post
Share on other sites

Check this: http://docs.phaser.io/Phaser.Physics.Arcade.html#TILE_BIAS

It fixes tunneling on lower fps but if you set it too high you character will also "climb" from the sides to the top. In my case I got good results with TILE_BIAS = 50

 

The problem is probably that arcade physics only checks for overlaps between the object and the tile in each frame, so on very low fps you object just teleports from one side of the tile to the other without ever touching it. http://en.wikipedia.org/wiki/Collision_detection#A_posteriori_.28discrete.29_versus_a_priori_.28continuous.29

Share this post


Link to post
Share on other sites

Just tested. No problems at all on Nexus 4 now running through Webview+ on CocoonJS. Only managed to get it fall out once on regular Chrome browser, so very pleased with that enhancement.

 

For anyone else struggling with this issue, I added this code on the update function:

 

this.game.physics.arcade.collide(this.sprite, this.layer);

this.game.physics.arcade.TILE_BIAS = 50;

 

Sprite = player and layer = tilemap layer

 

Again many thanks to NOID, didn't know that existed and I don't think I'd have worked that out from the docs  :D

Share this post


Link to post
Share on other sites

I have it in the create function right after initializing the physics system.

        this.game.physics.startSystem(Phaser.Physics.ARCADE);        this.game.physics.arcade.TILE_BIAS = 50;

I think you just need to set it once.

 

Now I reread to forum post where Rich mentioned TILE_BIAS and I noticed he also mentioned tilePadding which is set per sprite, but I never tried it so I don't know if it works better than TILE_BIAS

http://docs.phaser.io/Phaser.Physics.Arcade.Body.html#tilePadding

Share this post


Link to post
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...

  • Recently Browsing   0 members

    No registered users viewing this page.