Jump to content

Arcade Physics bug?


Sturb
 Share

Recommended Posts

Hey guys! I'm making an endless runner and I'm running into a weird issue with Arcade physics. Because my game is an endless running, I'm anchoring my player on the screen and moving the objects towards the player instead of using the camera. My issue is that I get collision events however none of the body.blocked booleans are being set, so I know a collision happens, but I don't know which side it happens on (up, down, or left). I'm checking for collision like such:

this.game.physics.arcade.collide(sprite, this.chunks[0], levelHandler, null, ctx);
this.game.physics.arcade.collide(sprite, this.chunks[1], levelHandler, null, ctx);
this.game.physics.arcade.collide(sprite, this.chunks[2], levelHandler, null, ctx);

Basically, what I'm doing is I spawn three chunks (or segments) of objects and position them one screen length apart from each other. I then scroll each group on screen towards the player. When a chunk is scrolled off the opposite side of the screen, I reposition it back behind the last chunk in the list so it can be scrolled back on towards the player.

My 'levelHandler' is being called properly, and it's giving my the object that the player collided with. Again, my issue is the object.body.blocked booleans aren't being set, so I don't know whether the player hit the left side, top, or bottom of the object.

Would this be because I'm not moving the objects by applying a velocity to the object's body? I'm moving the parent group of the objects so I don't have to iterate through all my objects to do that. 
Is there another way to get the information I want? Or am I going to have to write my own detection to get which side was hit after the collision happened?

Link to comment
Share on other sites

Hmm.. body.touching on both my player and the object are also all false (none: true) at the time of collision. Does Phaser's Arcade physics not like it when you manually set position of the object instead of applying a velocity to it?

Link to comment
Share on other sites

It sounds like it may be a combination of that and the fact you're moving the objects via their parent group. Phaser works out where a collision is taking place on an object and (if necessary and required) how then to separate them via the velocity of at least one of the objects. If you're moving objects as a child of a group, then they're not really 'moving' as far as Phaser can tell, they're simply being visually translated.

Link to comment
Share on other sites

Quote

then they're not really 'moving' as far as Phaser can tell, they're simply being visually translated.

I was wondering if that was possibly happening. If that's the case then I would be confused as to why I'm getting a collision event when I would expect one. That would indicate to me that the bodies are indeed moving. 

Link to comment
Share on other sites

Make sure you're testing `body.touching` either in the collision callback or after the `collide` call.

As long as `collide` is returning true I think that Arcade Physics must be marking the 2 bodies as touching.

All the same, if you're not using `velocity` at all, try setting `body.moves = false` and use `arcade.overlap` instead of collide.

And try samme/phaser-plugin-debug-arcade-physics!

Link to comment
Share on other sites

18 hours ago, samme said:

Make sure you're testing `body.touching` either in the collision callback or after the `collide` call.

As long as `collide` is returning true I think that Arcade Physics must be marking the 2 bodies as touching.

All the same, if you're not using `velocity` at all, try setting `body.moves = false` and use `arcade.overlap` instead of collide.

And try samme/phaser-plugin-debug-arcade-physics!

Setting 'body.moves = false' has seemed to fix my issue. I didn't have to change 'arcade.collide' to overlap, however I'll keep that in mind if anything else comes up. Thanks a lot samme!

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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