Jump to content

Overlap passing through in high velocities


raphaklaus
 Share

Recommended Posts

Hello! 

I'm new with Phaser and Game Dev itself. I've searched for this topic and found nothing, sorry if in some way its duplicated. :)

I've created Overlapping Sprites Collision in my game.

Exists 2 sprites, one with 70 velocity (not velocity because they are not bodies, but its a x axis increment in update method which I think is the problem), and the other static.

When the two sprites overlaps, the "collision" happen, but kind "later". The moving sprite passes through the lying one.

Is this related to timers or with the x increment I report above? I've uploaded a image that illustrates what is occurring.

Using Arcade Physics seems to be okay.

I hope I've make myself clear/understandable :lol: 

example.png

Link to comment
Share on other sites

Hi squilibob! Thank you for your reply!

Quote

are you moving the sprites one pixel at a time or all at once?

I'm moving all at once. Like this code:

if (this.gameState.started)
  this.gameObjects.ground.x -= 5;
Quote

Instead of doing player.x += 70 you should be doing a for loop 70 times moving player.x++

Hmm, this way seems to not work (although I've not tested), but it seems to be a workaround, or am I wrong?

Link to comment
Share on other sites

2 hours ago, raphaklaus said:

Hi squilibob! Thank you for your reply!

I'm moving all at once. Like this code:


if (this.gameState.started)
  this.gameObjects.ground.x -= 5;

Hmm, this way seems to not work (although I've not tested), but it seems to be a workaround, or am I wrong?

You can allow sprite collision to trigger as soon as your object collides by moving it 1 pixel at a time or you can manually check if an object will collide before moving it by writing code to handle that

Link to comment
Share on other sites

After some research I've realized what was going on. Feel free to correct me. :)

The moving object is moving fast, fast than collision can detect. A CCD (Continuous Collision Detection) would help in this case, and I will leave a link to help others understand: http://www.stencyl.com/help/view/continuous-collision-detection/

The for strategy seems to work, but its kinda homebrew algorithm to CCD and has performance trade-offs.

Is there another way to achieve the same result? I'd love to see how other game developers are overcoming this issue.

In time, Box2D and MatterJS physics systems has CCD support, would love to see P2 and Arcade having this out of the box too. 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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