I have a two objects colliding with each other. I am testing for the collision with if(ob1.hitTestObject(ob2)){//do something }. Is there a way to determine which side of the object was hit, i.e. if ob2 is a square, which side of the square was collided with?
|
|
|||
|
|
|
The hitTest method provided by flash won't give you such an information. If you have two squares, you can simply calculate the vector between their center-points and use that to determine the side. For arbitrarily shaped objects, this won't work though. Another option is to have "sensor" points on your object, eg. top, left, right, bottom, and do a hit-test for each of these points against the other shape. |
|||
|
|
What the
For example in your scenario you take collision with certain points to mean that the object has collided against a certain side of the object. |
|||
|
|
|
In 2D you can know which side of a segment is a point using the signed area of a triangle. Let :
The SignedArea will be positive if ABP are oriented counterclockwise around the triangle, and negative if oriented clockwise. Thus,
In 3D you can know which side of a surface is a point using dot product and cross product. But as I guess your problem is a 2D problem, this should not be required. |
|||||
|
