# Handling none rectangular sprite collisions

## Recommended Posts

https://github.com/kittykatattack/learningPixi#keyboard

Was reading though the above link after a helpful person replied to a post on here. I read about the rectangular collision detection however I was wondering if there was a way to determine in a non rectangular image was used for the sprite to detect collision between the image.

Say for example I had a sprite that contained a texture of a beach all image. Can I detect 3 beach balls with circular images if they have collided and maybe even what pixels "bumped" in relation to the center of the sprite to send them bouncing off as if they collided in real life?

##### Share on other sites

In this scenario your going to want to use circular detection in order to get more accurate collision.

In rectangular collision, your checking what x and y axis the 2 objects collided at, this is different in circular collision as instead your trying to determine what angle they collided at.

Using the center points and the radius's of the circles used for collision you can find what point they collide, and from the angle of collision you can work out a collision vector.

Using physics you can work out what velocity the balls leave the collision at from the collision vector + their entry speeds.

Edit: just noticed pixi has a circle class: http://www.goodboydigital.com/pixijs/docs/classes/Circle.html if your using pixi rects then use this instead and you should be good. Also if you don't feel like doing the physics part yourself there's hundreds of libraries designed to do physics, i would suggest something like box2d to make your life easier.

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

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.