Get which side of a body collides

  ... the Physics Box2D Extension for AndEngine.

Get which side of a body collides

Postby fatal » Sat Mar 10, 2012 2:31 pm

Hello!

I'm new to andengine and box2d too, and i'm trying to create an arkanoid clone. I have a ball and bricks, all sprites has a body attached. How can I get which side of the brick's body collides with the ball's body in beginContact?

First i was created four lines for every brick (one for each side), works like a charm but it's really slow on an armv6 phone if there are lots of bricks on the scene. Anyone can help me, how can i make it faster?

Sorry for my poor english.


Edit.: I figured it out :)
User avatar
fatal
 
Posts: 468
Joined: Sun Jan 08, 2012 2:20 am
Location: Budapest, Hungary

Re: Get which side of a body collides

Postby arrecio » Sun Mar 11, 2012 7:36 pm

bricks are static non-rotated rectangles? Just check the relationship betwen positions at contact:

for example (assuming ball and brick are in contact):

if (ball.x-ball.radius/2 > brick.rightside.x) -> u can asume ball is hitting the right side

and something like it with other sides

PD: i have not tested it
arrecio
 
Posts: 2
Joined: Sun Mar 11, 2012 5:00 pm

Re: Get which side of a body collides

Postby fatal » Mon Mar 12, 2012 3:34 pm

arrecio wrote:bricks are static non-rotated rectangles? Just check the relationship betwen positions at contact:

for example (assuming ball and brick are in contact):

if (ball.x-ball.radius/2 > brick.rightside.x) -> u can asume ball is hitting the right side

and something like it with other sides

PD: i have not tested it


Yes, they are static and non rotated, but that didn't work. However I can get the contact point from the manifold object, and i check which side is the nearest for that point. :)

By the way, thanks for the answer. :)
User avatar
fatal
 
Posts: 468
Joined: Sun Jan 08, 2012 2:20 am
Location: Budapest, Hungary


Return to Physics Box2D

Who is online

Users browsing this forum: Alexa [Bot] and 7 guests