Jump to content

Object doesn't bounce as anticipated of other sprites. Is there an object used only for physics.body for collisions?


Recommended Posts



I'd like to ask for and advice.


In the picture below is my current scene. On the right side I described my problem, I'll try to explain it here with words.


I'm having blue sprite (blue rectangle) and number of green (grey dotted) sprites on both sides of the screen (black lines show where each sprit ends). I'd like the blue sprite to bounce of the green as a wall, but what I get instead is that whenever blue sprit hits the contact point/side it bounces backwards (described with purple arrows). If if hits in any other part of the green sprite then it bounces off correctly (discribed with red arrows).

(green rectangles move downwards creating infinite lane - until some point of the level is reached when the green rectangles will stop at half of the scene in y-axis)


I was wondering if there is a way how to turn this around in phaser? I though mayber creating some object which can get body and cover side areas with it (though don't know which part of phaser to use for it), or any other way please?


Just for the record:

I'm using arcade physics, phaser version 2.3.0.

 - blue rectangle: bounce(1,1)

 - green rectangles (phaser.group): bounce(1,1), immovable = true, velocity.y = 40



Thank you very much for any advice you can give me :) .





I'm currently using one pixel (picture) sprite with large body on both sides for collisions, and green rectangle sprites with velocity over it (they are not called for collision checks), but it still feels kinda weird to solve it like this. I hope someone can give me a better advice? :-)

Edited by AzraelTycka
Link to comment
Share on other sites

Maybe instead of moving the green sprites vertically, just animate the white stripes and keep them level with the what-look-to-me-to-be-Spy-Hunter-cars.


So the green things don't move, don't collide with each other, and you don't have edge problems?


Alternately, animate the white stripes moving but have invisible sprites to collide with so you don't have the edge problem?

Link to comment
Share on other sites

You could:

  • Try to make you "walls" colision sighly bigger (so the walls have some pixels on top of the next one, and you're sure you'll not have a gap between 2)
  • Add a round shape to your moving object (a circle with a sighly bigger diameter than the current body) but it'll be a problem if you can hit something in front of you
  • Use a custom shape (polygon): Basically a rectangle with cut angles like this
/  \
|  |
|  |
|  |
|  |
Link to comment
Share on other sites


Distance is always zero, it's basically a "wall" made of different parts with different animations per part.



I had a similar idea as your first one, but the problem didn't disappear. I wanted to avoid custom collisions this time, I'm trying to heck it with phaser as much as possible to know it better :-).


For now I added one more sprite per side (two in totals), gave them body and set its width to green rectangle and height to the whole world (screen) and collision is checked between these two and blue rectangle.


Seems like in iteration blue rectangle partially overlaps with other bodies while it's not a problem when facing longer side of the rectangle it becomes a problem when it overlaps on a boundary where the collision is probably handled with bottom side (boundary) as well - probably :-).

Link to comment
Share on other sites


  • Recently Browsing   0 members

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