Jump to content

Having trouble detecting collisions in my game


VizuaaLOG
 Share

Recommended Posts

Hi all,

 

In my game I have circles which are spawned and then are tweened over time to adjust their scale. This is working however, I want to detect when two circles collide and run a function when this happens. All the circles are in a group.

 

I have tried using arcade physics however after researching I found out that collision detection only works if the sprites have motion, and mine do not they are just being tweened, arcade physics also doesn't have a circular hit box. I then decided to look into P2 physics which does work and the collisions are detected, however, it causes the circles to move off screen, this can be solved by making each circle static but then collisions are not detected between them.

 

Also, without the circles being static although the collisions are detected they are detected when the circles are not even touching.

 

Thanks for your help.

Link to comment
Share on other sites

I have tried that as well but because all the circles are in one group it seems to count the entire group as being overlapped even when there is only one circle on the screen. Its like Phaser counts a group as being the full size of the stage and so the circle is always overlapping the group.

 

Edit: looking at the example I see that is without physics which might work. Although is there a way to use circles instead of rectangles for the bounds? As using rectangles would mean a collision would be made even though it wasn't.

Link to comment
Share on other sites

I haven't really tried implementing anything but, can you not use circle instead of rectangle in the collision function ? Phaser.Rectangle.intersects(boundsA, boundsB)   ->    Phaser.Circle.intersects(boundsA, boundsB);      or otherwise perform

some kind of logic check in the function like if  boundsA !== boundsB then perform the intersect so only seperate circles intersect?

Link to comment
Share on other sites

I haven't really tried implementing anything but, can you not use circle instead of rectangle in the collision function ? Phaser.Rectangle.intersects(boundsA, boundsB)   ->    Phaser.Circle.intersects(boundsA, boundsB);      or otherwise perform

some kind of logic check in the function like if  boundsA !== boundsB then perform the intersect so only seperate circles intersect?

 

Yes, I looked at the example you provided and decided to experiment and indeed what you said is correct, except I don't need to get the bounds of the circle like the example does with the rectangle instead the intersects function on the circle class just takes two circles, and so I created a two for loops to loop over each alive circle and then each alive circle again and see if any are intersecting, apart from its self, if they are then they have collided. Thanks for your answers to help come up with the solution much appreciated.

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