VizuaaLOG Posted January 2, 2015 Share Posted January 2, 2015 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 More sharing options...
temporalix Posted January 2, 2015 Share Posted January 2, 2015 (edited) could using overlap not maybe help?here is a link in examples - http://examples.phaser.io/_site/view_full.html?d=sprites&f=overlap+tween+without+physics.js&t=overlap%20tween%20without%20physics Edited January 2, 2015 by temporalix Link to comment Share on other sites More sharing options...
VizuaaLOG Posted January 2, 2015 Author Share Posted January 2, 2015 could using overlap not maybe help?here is a link in examples - http://examples.phaser.io/_site/view_full.html?d=sprites&f=overlap+tween+without+physics.js&t=overlap%20tween%20without%20physicsI 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 More sharing options...
temporalix Posted January 2, 2015 Share Posted January 2, 2015 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 performsome 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 More sharing options...
VizuaaLOG Posted January 2, 2015 Author Share Posted January 2, 2015 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 performsome 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 More sharing options...
Recommended Posts